build: :construction_worker: Build all-in-one Docker image
Tim Izzo tim@octree.ch
Wed, 07 Sep 2022 14:55:02 +0200
12 files changed,
118 insertions(+),
64 deletions(-)
A
.dockerignore
@@ -0,0 +1,8 @@
+**/*/node_modules +**/*/Dockerfile +**/*/.dockerignore +**/*/.env +backend/.cache +backend/.tmp +backend/build +frontend/.next
M
.gitlab-ci.yml
→
.gitlab-ci.yml
@@ -2,22 +2,5 @@ include:
- project: o/infra/templates file: /gitlab-ci/includes/jobs.yaml -Build NextJS: +Build: extends: .build - variables: - CI_PROJECT_DIR: frontend/ - CI_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE/next - rules: - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - changes: - - frontend/**/* - -Build Strapi: - extends: .build - variables: - CI_PROJECT_DIR: backend/ - CI_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE/strapi - rules: - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - changes: - - backend/**/*
A
Dockerfile
@@ -0,0 +1,18 @@
+FROM node:16-alpine + +VOLUME /srv/app/backend/node_modules +VOLUME /srv/app/backend/build +VOLUME /srv/app/backend/public/uploads +VOLUME /srv/app/frontend/node_modules +VOLUME /srv/app/frontend/.next + +EXPOSE 80 +WORKDIR /srv/app + +RUN apk add --no-cache nginx && yarn global add pm2 +COPY ./frontend /srv/app/frontend +COPY ./backend /srv/app/backend +COPY ./ecosystem.config.js /srv/app/ +COPY ./nginx.conf /etc/nginx/http.d/default.conf + +CMD nginx && pm2-runtime start ecosystem.config.js
D
backend/.dockerignore
@@ -1,7 +0,0 @@
-node_modules/ -.cache -.tmp -build -.env -Dockerfile -.dockerignore
M
backend/.env.example
→
backend/.env.example
@@ -1,5 +1,4 @@
HOST=0.0.0.0 -PORT=1337 APP_KEYS="toBeModified1,toBeModified2" API_TOKEN_SALT=tobemodified ADMIN_JWT_SECRET=tobemodified@@ -8,4 +7,5 @@ SENTRY_DSN=
SMTP_HOST= SMTP_PORT= SMTP_USERNAME= -SMTP_PASSWORD=+SMTP_PASSWORD= +STRAPI_URL=http://localhost:8080
D
backend/Dockerfile
@@ -1,11 +0,0 @@
-FROM node:14-alpine - -WORKDIR /srv/app -COPY ./ . - -EXPOSE 1337 -VOLUME /srv/app/public/uploads -VOLUME /srv/app/node_modules -VOLUME /srv/app/build - -CMD ["yarn", "start"]
M
backend/README.md
→
backend/README.md
@@ -51,7 +51,3 @@
- [Discord](https://discord.strapi.io) - Come chat with the Strapi community including the core team. - [Forum](https://forum.strapi.io/) - Place to discuss, ask questions and find answers, show your Strapi project and get feedback or just talk with other Community members. - [Awesome Strapi](https://github.com/strapi/awesome-strapi) - A curated list of awesome things related to Strapi. - ---- - -<sub>🤫 Psst! [Strapi is hiring](https://strapi.io/careers).</sub>
M
backend/config/middlewares.ts
→
backend/config/middlewares.ts
@@ -26,11 +26,13 @@ "strapi::body",
"strapi::session", "strapi::favicon", "strapi::public", - { - resolve: "./src/middlewares/graphql-logger", - config: { - enabled: true, - conf: {}, - }, - }, + + // Waiting for https://github.com/strapi/strapi/pull/14280 to be resolved + // { + // resolve: "./src/middlewares/graphql-logger", + // config: { + // enabled: true, + // conf: {}, + // }, + // }, ];
A
ecosystem.config.js
@@ -0,0 +1,21 @@
+module.exports = { + apps: [ + { + name: "strapi", + cwd: "backend/", + script: "yarn", + args: "start", + interpreter: "sh", + restart_delay: 10000, + max_restarts: 10, + }, + { + name: "next", + cwd: "frontend/", + script: "yarn", + args: "start", + interpreter: "sh", + restart_delay: 10000, + }, + ], +};
D
frontend/Dockerfile
@@ -1,11 +0,0 @@
-FROM node:16-alpine - -WORKDIR /srv/app - -COPY . . - -EXPOSE 3000 -VOLUME /srv/app/node_modules -VOLUME /srv/app/.next - -CMD ["yarn", "start"]
A
nginx.conf
@@ -0,0 +1,59 @@
+upstream strapi { + server localhost:1337; +} + +upstream nextjs { + server localhost:3000; +} + +server { + listen 80 default_server; + listen [::]:80 default_server; + + proxy_http_version 1.1; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Server $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $http_host; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_pass_request_headers on; + + location /graphql { + proxy_pass http://strapi; + } + location /api { + proxy_pass http://strapi; + } + location /admin { + proxy_pass http://strapi; + } + location /i18n { + proxy_pass http://strapi; + } + location /content-manager { + proxy_pass http://strapi; + } + location /email-designer { + proxy_pass http://strapi; + } + location /content-type-builder { + proxy_pass http://strapi; + } + location /upload { + proxy_pass http://strapi; + } + location /users-permissions { + proxy_pass http://strapi; + } + location /email { + proxy_pass http://strapi; + } + + + location / { + proxy_pass http://nextjs; + } +}