From 0aa9dffd7542be4a6b636867867d99326e6e200d Mon Sep 17 00:00:00 2001 From: Sangelo Date: Fri, 22 Mar 2024 11:19:46 +0100 Subject: [PATCH] Initial Docker Automatisation Work --- Dockerfile | 31 +++++++++++++++++++++++++++++++ build.sh | 5 +++++ docker-compose.build.yml | 10 ++++++++++ docker-compose.yml | 0 4 files changed, 46 insertions(+) create mode 100644 Dockerfile create mode 100755 build.sh create mode 100644 docker-compose.build.yml create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8296734 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# Builder stage +FROM node:20-alpine AS builder + +# Set the working directory in the container +WORKDIR /app + +# Copy the repository contents into the container +COPY . . + +# Install dependencies and build the site. Output directory will be /app/build +RUN yarn install && yarn run build + +# No need to move /app/build here + +# Final stage +FROM caddy:2-alpine + +# Set the working directory in the container +WORKDIR /web + +# Copy the build directory from the builder stage to /web +COPY --from=builder /app/build /web + +# Caddyfile configuration to serve files from /web +RUN echo -e ":80 {\n root * /web\n file_server\n}" > /etc/caddy/Caddyfile + +# Expose port 80 +EXPOSE 80 + +# Start Caddy with the specified Caddyfile +CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"] diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..30bb601 --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +sudo docker compose -f docker-compose.build.yml down && \ +#sudo docker compose -f docker-compose.build.yml rm --all && \ +sudo docker compose -f docker-compose.build.yml build --no-cache && \ +sudo docker compose -f docker-compose.build.yml up -d --force-recreate && \ +watch -n 1 sudo docker compose -f docker-compose.build.yml ps diff --git a/docker-compose.build.yml b/docker-compose.build.yml new file mode 100644 index 0000000..0fb6a7f --- /dev/null +++ b/docker-compose.build.yml @@ -0,0 +1,10 @@ +version: '3.8' + +services: + web: + build: + context: . + dockerfile: Dockerfile + no_cache: true + ports: + - "3000:80" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e69de29