From 6a3d510cada8c3583a3293ade2e8f73a8777e9f9 Mon Sep 17 00:00:00 2001 From: cami Date: Wed, 1 Sep 2021 02:20:53 +0200 Subject: [PATCH 1/2] Change Dockerfiles and docker-compose file The reason for this change is to reduce the image size for the different containers --- backend/.dockerignore | 1 + backend/Dockerfile | 22 +++++++++++++++------- backend/Dockerfile.prod | 20 ++++++++++++-------- docker-compose.prod.yml | 21 +++++++++++++++++++++ frontend/.dockerignore | 18 +++++++++++------- frontend/Dockerfile | 6 ++++-- frontend/Dockerfile.prod | 15 ++++++++++----- 7 files changed, 74 insertions(+), 29 deletions(-) create mode 100644 backend/.dockerignore create mode 100644 docker-compose.prod.yml diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1 @@ +venv diff --git a/backend/Dockerfile b/backend/Dockerfile index 4fde811..0cc72e8 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,11 +1,19 @@ -FROM python +FROM python:slim as base +FROM base as builder + +RUN mkdir /install +WORKDIR /install + +COPY requirements.txt /requirements.txt + +RUN pip install --prefix=/install -r /requirements.txt + +FROM base + +COPY --from=builder /install /usr/local + +COPY /src /app WORKDIR /app -COPY requirements.txt . - -RUN pip install -r requirements.txt - -COPY /src . - CMD [ "flask", "run" ] diff --git a/backend/Dockerfile.prod b/backend/Dockerfile.prod index 61f536d..03fb75e 100644 --- a/backend/Dockerfile.prod +++ b/backend/Dockerfile.prod @@ -1,15 +1,19 @@ -FROM python - -WORKDIR /app +FROM python:slim as base RUN apt-get -y update && apt-get -y upgrade -COPY requirements.txt . +FROM base as builder +RUN mkdir /install +WORKDIR /install -RUN apt-get -y install sqlite3 +COPY requirements.txt /requirements.txt +RUN pip install --prefix=/install -r /requirements.txt -RUN pip install -r requirements.txt +FROM base -COPY /src . +COPY --from=builder /install /usr/local -CMD [ "python", "app.py" ] +COPY /src /app +WORKDIR /app + +CMD [ "flask", "run" ] diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..99bf888 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,21 @@ +version: '3.7' + +services: + frontend-prod: + container_name: frontend-lettergen + build: + context: ./frontend + dockerfile: Dockerfile.prod + ports: + - 127.0.0.1:3000:80 + backend-prod: + container_name: backend-lettergen + build: + context: ./backend + dockerfile: Dockerfile.prod + ports: + - 127.0.0.1:5000:5000 + environment: + DEBUG: "no" + PORT: 5050 + HOST: "0.0.0.0" diff --git a/frontend/.dockerignore b/frontend/.dockerignore index 4233e68..fe0351e 100644 --- a/frontend/.dockerignore +++ b/frontend/.dockerignore @@ -1,8 +1,12 @@ -node_modules -npm-debug.log -build -.dockerignore +**/node_modules/ **/.git -**/.DS_Store -**/node_modules -.env +**/README.md +**/LICENSE +**/.vscode +**/npm-debug.log +**/coverage +**/.env +**/.editorconfig +**/.aws +**/dist + diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 7b63a8a..db25474 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,4 +1,4 @@ -FROM node:latest +FROM node:slim AS build # set working directory WORKDIR /app @@ -10,7 +10,9 @@ ENV PATH /app/node_modules/.bin:$PATH COPY package.json ./ COPY package-lock.json ./ -RUN npm install +RUN npm install && npm cache clean --force + +EXPOSE 3000 # add app COPY . ./ diff --git a/frontend/Dockerfile.prod b/frontend/Dockerfile.prod index 82892dc..8626815 100644 --- a/frontend/Dockerfile.prod +++ b/frontend/Dockerfile.prod @@ -1,13 +1,18 @@ -FROM node:latest as build +FROM node:slim as build + WORKDIR /app + ENV PATH /app/node_modules/.bin:$PATH + COPY package.json ./ COPY package-lock.json ./ -RUN npm ci --silent -COPY . ./ -RUN npm run build -FROM nginx:latest +RUN npm ci --production && npm cache clean --force +COPY . ./ +RUN npm run build + +FROM nginx:alpine +RUN apk -U upgrade COPY --from=build /app/build /usr/share/nginx/html RUN rm /etc/nginx/conf.d/default.conf COPY nginx/nginx.conf /etc/nginx/conf.d -- 2.45.2 From ef92bffa419bad565063cdc4f08e1c588291123a Mon Sep 17 00:00:00 2001 From: cami Date: Wed, 29 Sep 2021 02:06:21 +0200 Subject: [PATCH 2/2] Retry build.. --- README.md | 4 +++- start.sh | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 79e9c8f..ee70a1f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # LaTeX-Brief-Webseite -This is a small website to easily set a letter in LaTeX \ No newline at end of file +[![Build Status](https://ci.sp-codes.de/api/badges/cami/Brief-Generator/status.svg)](https://ci.sp-codes.de/cami/Brief-Generator) + +This is a small website to easily set a letter in LaTeX diff --git a/start.sh b/start.sh index 8272eec..6b61956 100644 --- a/start.sh +++ b/start.sh @@ -4,6 +4,4 @@ podman stop frontend-dev podman stop backend-dev podman rm frontend-dev podman rm backend-dev -podman rmi localhost/latex-brief-webseite_backend-dev -podman rmi localhost/latex-brief-webseite_frontend-dev podman-compose up --build -- 2.45.2