From 27bb7da1d722a4ac9f45e0cc8e27a33ec69e618e Mon Sep 17 00:00:00 2001 From: ScribblerCoder Date: Tue, 2 Apr 2024 01:59:52 +0300 Subject: [PATCH 1/5] add dockerfile and compose to run Coup --- .dockerignore | 8 ++++++++ Dockerfile | 31 +++++++++++++++++++++++++++++++ docker-compose.yml | 10 ++++++++++ 3 files changed, 49 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..397c9b3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +node_modules +npm-debug.log +Dockerfile* +.dockerignore +.git +.gitignore +treason*.log* +.yarnrc diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f1405de --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM node:lts-alpine as builder + +# Install dependencies +RUN apk add --no-cache git + +# Initialize the working directory +WORKDIR /app + +# Copy package.json +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy the source code +COPY . . + +# Prune to production dependencies +RUN npm prune --production + + +# Final image +FROM node:lts-alpine + +WORKDIR /app + +COPY --from=builder /app ./ + +# Expose the port and start the application +EXPOSE 8080 +CMD ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bd8c7e8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3' + +services: + treason: + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:8080" + \ No newline at end of file From 35f5939458d6718355f0fa69482a81991878cc10 Mon Sep 17 00:00:00 2001 From: ScribblerCoder Date: Mon, 15 Apr 2024 00:51:26 +0300 Subject: [PATCH 2/5] move docker related files --- Dockerfile => docker/Dockerfile | 6 +++--- docker-compose.yml => docker/docker-compose.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename Dockerfile => docker/Dockerfile (86%) rename docker-compose.yml => docker/docker-compose.yml (59%) diff --git a/Dockerfile b/docker/Dockerfile similarity index 86% rename from Dockerfile rename to docker/Dockerfile index f1405de..4d69112 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -7,20 +7,20 @@ RUN apk add --no-cache git WORKDIR /app # Copy package.json -COPY package*.json ./ +COPY ../package*.json ./ # Install dependencies RUN npm install # Copy the source code -COPY . . +COPY ../ . # Prune to production dependencies RUN npm prune --production # Final image -FROM node:lts-alpine +FROM node:lts-alpine as server WORKDIR /app diff --git a/docker-compose.yml b/docker/docker-compose.yml similarity index 59% rename from docker-compose.yml rename to docker/docker-compose.yml index bd8c7e8..2d54684 100644 --- a/docker-compose.yml +++ b/docker/docker-compose.yml @@ -3,8 +3,8 @@ version: '3' services: treason: build: - context: . - dockerfile: Dockerfile + context: ../ + dockerfile: docker/Dockerfile ports: - "8080:8080" \ No newline at end of file From 9a5e370d05272ad332611dfc60efa0dc674ca800 Mon Sep 17 00:00:00 2001 From: ScribblerCoder Date: Mon, 15 Apr 2024 00:59:09 +0300 Subject: [PATCH 3/5] fix docker context --- docker/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 4d69112..b591e67 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -7,13 +7,13 @@ RUN apk add --no-cache git WORKDIR /app # Copy package.json -COPY ../package*.json ./ +COPY package*.json ./ # Install dependencies RUN npm install # Copy the source code -COPY ../ . +COPY . . # Prune to production dependencies RUN npm prune --production From c4853248b8464f4f6ae0ee4a2aa73e47ac846668 Mon Sep 17 00:00:00 2001 From: ScribblerCoder Date: Mon, 15 Apr 2024 01:03:33 +0300 Subject: [PATCH 4/5] add docker compose instructions --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 0201690..169a4d0 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,13 @@ Then open `http://localhost:8080` in one or more browser windows. For an explana I use BrowserStack for testing - thanks for the free account guys! +Docker +-- +You could also use docker compose to run the server. Just run: + + docker compose -f docker/docker-compose.yml up + + AI -- From 83ad148e273a0524c3800a4624e676b00bdd3fa7 Mon Sep 17 00:00:00 2001 From: ScribblerCoder <35840617+ScribblerCoder@users.noreply.github.com> Date: Tue, 16 Apr 2024 19:36:48 +0300 Subject: [PATCH 5/5] Update comments --- docker/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index b591e67..3fac15c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,3 +1,5 @@ +# A multistage Dockerfile. The first stage is the builder image then +# we copy all needed dependencies to the final image to reduce size FROM node:lts-alpine as builder # Install dependencies @@ -24,6 +26,7 @@ FROM node:lts-alpine as server WORKDIR /app +# Copy the application from the previous stage (without extra packages installed through apk/apt) COPY --from=builder /app ./ # Expose the port and start the application