From 5414f3b3711a50a63f118a63c2bade3cfe3aa5f5 Mon Sep 17 00:00:00 2001 From: Michael Schramm Date: Sun, 2 May 2021 15:53:01 +0200 Subject: [PATCH] - switched to supervisord based combined container - heroku deployments --- CHANGELOG.md | 4 +++ Dockerfile | 68 +++++++++++++++++++++++++++++----------------- api | 2 +- app.json | 6 +++- docker-compose.yml | 34 ++++++++++------------- nginx.conf | 15 ++++++++++ supervisord.conf | 25 +++++++++++++++++ ui | 2 +- 8 files changed, 109 insertions(+), 47 deletions(-) create mode 100644 nginx.conf create mode 100644 supervisord.conf diff --git a/CHANGELOG.md b/CHANGELOG.md index d3cc343a..7b87dbc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed +- switched to supervisord based combined container + ### Fixed +- heroku deployments + ### Security ## [0.9.9] - 2021-02-14 diff --git a/Dockerfile b/Dockerfile index 113b230f..a0165b47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,14 @@ -## Build API -FROM node:14-alpine as api +## Build UI +FROM node:14-alpine as ui -WORKDIR /usr/src/app - -COPY ui/ . - -RUN yarn install --frozen-lockfile -RUN yarn export - -## Build APP -FROM node:14-alpine as app -LABEL maintainer="OhMyForm " - -WORKDIR /usr/src/app +WORKDIR /usr/src/ui RUN apk update && apk add curl bash && rm -rf /var/cache/apk/* # install node-prune (https://github.com/tj/node-prune) RUN curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /usr/local/bin - -COPY api/ . -COPY --from=api /usr/src/app/out /usr/src/app/public +COPY ui/ . RUN yarn install --frozen-lockfile RUN yarn build @@ -32,22 +19,53 @@ RUN npm prune --production # run node prune RUN /usr/local/bin/node-prune -## Glue -RUN touch /usr/src/app/src/schema.gql && chown 9999:9999 /usr/src/app/src/schema.gql +## Build API +FROM node:14-alpine as api +LABEL maintainer="OhMyForm " + +WORKDIR /usr/src/api + +RUN apk --update add curl bash && rm -rf /var/cache/apk/* + +# install node-prune (https://github.com/tj/node-prune) +RUN curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /usr/local/bin + +COPY api/ . + +RUN touch /usr/src/api/src/schema.gql && chown 9999:9999 /usr/src/api/src/schema.gql + +RUN yarn install --frozen-lockfile +RUN yarn build + +# remove development dependencies +RUN npm prune --production + +# run node prune +RUN /usr/local/bin/node-prune ## Production Image. FROM node:14-alpine -WORKDIR /usr/src/app -COPY --from=app /usr/src/app /usr/src/app +RUN apk --update add supervisor nginx && rm -rf /var/cache/apk/* + +WORKDIR /usr/src + +COPY --from=api /usr/src/api /usr/src/api +COPY --from=ui /usr/src/ui /usr/src/ui + RUN addgroup --gid 9999 ohmyform && adduser -D --uid 9999 -G ohmyform ohmyform -ENV PORT=3000 \ - SECRET_KEY=ChangeMe \ +ENV SECRET_KEY=ChangeMe \ CREATE_ADMIN=FALSE \ ADMIN_EMAIL=admin@ohmyform.com \ ADMIN_USERNAME=root \ ADMIN_PASSWORD=root EXPOSE 3000 -USER ohmyform -CMD [ "yarn", "start:prod" ] + +RUN mkdir /run/nginx/ +RUN touch /usr/src/supervisord.log && chmod 777 /usr/src/supervisord.log +COPY supervisord.conf /etc/supervisord.conf +COPY nginx.conf /etc/nginx/conf.d/ohmyform.conf + +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"] +# CMD [ "yarn", "start:prod" ] diff --git a/api b/api index e1670223..9327514e 160000 --- a/api +++ b/api @@ -1 +1 @@ -Subproject commit e1670223cfb84e221be15e820761640e6916e6f4 +Subproject commit 9327514e8345b1ef1e656610246a981fe93ac33c diff --git a/app.json b/app.json index b9f9520f..c7896623 100644 --- a/app.json +++ b/app.json @@ -34,7 +34,7 @@ }, "LOGIN_NOTE": { "description": "Note next to login form", - "value": "Either login with root:root or create your own account to test OhMyForm\n\nData will be deleted at arbitrary intervals!" + "value": "Welcome to your new OhMyForm instance, you can remove this login note in the dyno configuration!" }, "ADMIN_PASSWORD": { "description": "Password for your default admin account", @@ -55,6 +55,10 @@ "DATABASE_DRIVER": { "description": "Database Driver to use", "value": "postgres" + }, + "DATABASE_SSL": { + "description": "Use SSL Connection for database", + "value": "true" } }, "addons": [ diff --git a/docker-compose.yml b/docker-compose.yml index 2167dd07..ebc6e906 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,37 +7,33 @@ version: "3" services: redis: image: redis - mongo: - image: mongo - volumes: - - "./data/mongo:/data/db" ohmyform: build: . environment: CREATE_ADMIN: "TRUE" - MONGODB_URI: mongodb://mongo/ohmyform MAILER_URI: smtp://mail:1025 - PORT: 5000 + DATABASE_DRIVER: postgres + DATABASE_URL: postgresql://root:root@db:5432/ohmyform + LOGIN_NOTE: "login with root:root!" + SECRET_KEY: 12345 links: - - mongo + - db - redis - mail ports: - - "5000:5000" + - "5200:3000" depends_on: - - mongo + - db - redis mail: image: mailhog/mailhog ports: - - "5050:8025" - mongoexpress: - image: mongo-express + - "5051:8025" + db: + image: postgres:10-alpine + volumes: + - ./pg_data:/var/lib/postgresql/data environment: - ME_CONFIG_MONGODB_SERVER: mongo - ports: - - "5051:8081" - links: - - mongo - depends_on: - - mongo + POSTGRES_USER: root + POSTGRES_PASSWORD: root + POSTGRES_DB: ohmyform diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..62f533d1 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 3000; + + location / { + proxy_pass http://localhost:4000; + proxy_redirect off; + proxy_set_header Host $host; + } + + location /graphql { + proxy_pass http://localhost:4100; + proxy_redirect off; + proxy_set_header Host $host; + } +} diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 00000000..fff1c377 --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,25 @@ +[supervisord] +nodaemon=true + +[program:ui] +directory=/usr/src/ui +command=yarn next start -p 4000 +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 + +[program:api] +directory=/usr/src/api +command=yarn start:prod +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 + +[program:nginx] +command=nginx -g "daemon off;" +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/fd/1 +stderr_logfile_maxbytes=0 diff --git a/ui b/ui index 3d3614b8..c6cf6783 160000 --- a/ui +++ b/ui @@ -1 +1 @@ -Subproject commit 3d3614b88abf020f9435cf81e6b19420e95108c3 +Subproject commit c6cf6783b41333073169fc7c9bbc36df45a0047d