From ca59beda2f904dc5754c946968f470aacc30b64c Mon Sep 17 00:00:00 2001 From: Christoph Niehoff Date: Mon, 10 May 2021 16:01:04 +0200 Subject: [PATCH] Readded support for a single-container docker deployment as this is needed for the heroku example app --- .dockerignore | 1 + .travis.yml | 2 +- heroku/Dockerfile | 21 +++++++++++++++++++++ heroku/conf/nginx.conf | 20 ++++++++++++++++++++ heroku/conf/supervisord.conf | 20 ++++++++++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 heroku/Dockerfile create mode 100644 heroku/conf/nginx.conf create mode 100644 heroku/conf/supervisord.conf diff --git a/.dockerignore b/.dockerignore index a054123e..8b1e8e30 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,4 @@ deploy/ build/ db/ **/*.test.js +.heroku/ diff --git a/.travis.yml b/.travis.yml index 23c23a51..c32577ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ matrix: - echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin - echo "$HEROKU_API_KEY" | docker login -u "$HEROKU_USER" --password-stdin registry.heroku.com script: - - docker build -t $REPO:$COMMIT . + - docker build -f heroku/Dockerfile -t $REPO:$COMMIT . - docker tag $REPO:$COMMIT $REPO:latest - docker tag $REPO:$COMMIT $REPO:$TRAVIS_TAG - docker tag $REPO:$COMMIT $REPO:$TRAVIS_TAG diff --git a/heroku/Dockerfile b/heroku/Dockerfile new file mode 100644 index 00000000..48bf2d1d --- /dev/null +++ b/heroku/Dockerfile @@ -0,0 +1,21 @@ +FROM ubuntu:latest +WORKDIR /usr/src/app +ENV PORT 80 + +RUN apt-get update && apt-get install -y curl +RUN curl -sL https://deb.nodesource.com/setup_16.x | bash +RUN apt-get update && apt-get install -y nginx supervisor nodejs +RUN rm -rf /var/lib/apt/lists/* + +COPY package*.json ./ +RUN npm install +COPY . . +COPY heroku/conf/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY heroku/conf/nginx.conf /etc/nginx/sites-available/default + +RUN npm run build +RUN cp -a build/. /var/www/html/ + +# add support for $PORT env variable +CMD sed -i -e 's/$PORT/'"$PORT"'/g' /etc/nginx/sites-available/default && /usr/bin/supervisord + diff --git a/heroku/conf/nginx.conf b/heroku/conf/nginx.conf new file mode 100644 index 00000000..489a9b8d --- /dev/null +++ b/heroku/conf/nginx.conf @@ -0,0 +1,20 @@ +server { + listen $PORT; + root /var/www/html; + index index.html; + server_name _; + location / { + try_files $uri /index.html; + } + location /api/ { + proxy_pass http://localhost:8001/; + } + location /socket.io/ { + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_http_version 1.1; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_pass http://localhost:8000/socket.io/; + } +} diff --git a/heroku/conf/supervisord.conf b/heroku/conf/supervisord.conf new file mode 100644 index 00000000..393290d8 --- /dev/null +++ b/heroku/conf/supervisord.conf @@ -0,0 +1,20 @@ +[supervisord] +nodaemon=true + +[program:app] +directory=/usr/src/app +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +command=npm run server + +[program:nginx] +command=/usr/sbin/nginx -g "daemon off;" +priority=900 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +username=www-data +autorestart=true