Skip to content

Commit

Permalink
- switched to supervisord based combined container
Browse files Browse the repository at this point in the history
- heroku deployments
  • Loading branch information
wodka committed May 2, 2021
1 parent 46760ae commit 5414f3b
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 41 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 37 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
## Build API
FROM node:14-alpine as api
## Build UI
FROM node:14-alpine as ui

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 ui/ .

RUN yarn install --frozen-lockfile
RUN yarn export
RUN yarn build

# remove development dependencies
RUN npm prune --production

## Build APP
FROM node:14-alpine as app
# run node prune
RUN /usr/local/bin/node-prune

## Build API
FROM node:14-alpine as api
LABEL maintainer="OhMyForm <admin@ohmyform.com>"

WORKDIR /usr/src/app
WORKDIR /usr/src/api

RUN apk update && apk add curl bash && rm -rf /var/cache/apk/*
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/ .
COPY --from=api /usr/src/app/out /usr/src/app/public

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
Expand All @@ -32,22 +43,29 @@ 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

## 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" ]
2 changes: 1 addition & 1 deletion api
Submodule api updated 179 files
6 changes: 5 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -55,6 +55,10 @@
"DATABASE_DRIVER": {
"description": "Database Driver to use",
"value": "postgres"
},
"DATABASE_SSL": {
"description": "Use SSL Connection for database",
"value": "true"
}
},
"addons": [
Expand Down
34 changes: 15 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
25 changes: 25 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ui
Submodule ui updated 281 files

0 comments on commit 5414f3b

Please sign in to comment.