Skip to content

Commit

Permalink
Add production ready nginx docker image (#20)
Browse files Browse the repository at this point in the history
* Add build image

* Add working bitnami/nginx image

* Remove unnecessary comments

* Refactor the CI workflow

* Fix yarn caching and github actions timeout issue

* Fix workfloww trigger

* Remove yarn.lock file

* Fix yarn install timeout

* Fix docker image build trigger

* Revert "Remove yarn.lock file"

This reverts commit 1076932.

* Revert removal of yarn lock

* Increase yarn install timeout

* Increase yarn install timeout

* Change docker build image

* Add nginx conf

* Cleanup nginx.conf

* Remove yarn.lock

* Revert "Remove yarn.lock"

This reverts commit 51476e3.

* Fix workflow trigger

* Fix docker cpu architecture

* Fix docker cpu architecture

---------

Co-authored-by: Radovan Tomasik <tomasik.radova@gmail.com>
  • Loading branch information
RadovanTomik and Radovan Tomasik committed May 12, 2023
1 parent 54dfe7a commit d24de79
Show file tree
Hide file tree
Showing 6 changed files with 2,006 additions and 1,909 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
@@ -0,0 +1,3 @@
.github
oidc_mock
tests
34 changes: 12 additions & 22 deletions .github/workflows/docker-ci.yml → .github/workflows/CI.yml
@@ -1,38 +1,28 @@
name: Docker Image CI
name: CI pipeline

on:
schedule:
- cron: '0 10 * * *' # every day at 10am
push:


jobs:

build:

runs-on: ubuntu-latest

steps:

- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn'

- name: Install project dependencies
run: yarn --prefer-offline

- name: Build
run: yarn install && yarn build && ls -a
-
name: Set up QEMU
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USER }}
Expand All @@ -50,14 +40,14 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
-
name: Build and push
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
platforms: linux/arm64, linux/amd64
push: true
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
24 changes: 13 additions & 11 deletions Dockerfile
@@ -1,13 +1,15 @@
FROM node:19-alpine
RUN apk update
RUN apk upgrade
RUN apk add bash curl yarn
RUN yarn add vite
FROM node:20.1.0-alpine as build-stage
WORKDIR /app
COPY . /app
COPY ./dist /app
RUN chown -R 1001:1001 /app
EXPOSE 8080
RUN chmod +x start.sh
COPY . .
RUN yarn install --network-timeout 1000000000 --ignore-engines
RUN yarn build

FROM bitnami/nginx:1.24 as production-stage
WORKDIR /app
COPY --from=build-stage /app/dist .
COPY nginx.conf /opt/bitnami/nginx/conf/server_blocks/my_server_block.conf
COPY start.sh .
USER 0
RUN chmod -R g+rwx /app
USER 1001
CMD [ "./start.sh" ]
CMD ["./start.sh"]
27 changes: 27 additions & 0 deletions nginx.conf
@@ -0,0 +1,27 @@
server {
listen 8080;
server_name localhost;
root /app;
index index.html;

gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache";
}

location ^~ /config/ {
add_header Cache-Control "no-cache";
add_header X-Content-Type-Options nosniff;
}

location ~ \.(css|js)$ {
expires max;
add_header Cache-Control "public";
add_header X-Content-Type-Options nosniff;
}
}
4 changes: 2 additions & 2 deletions start.sh
@@ -1,7 +1,7 @@
#!/bin/bash

echo "Replacing env constants in JS"
for file in assets/*.js*;
for file in assets/index.*.js;
do
echo "Processing $file ...";

Expand All @@ -12,4 +12,4 @@ do

done

yarn run dev --host
exec nginx -g 'daemon off;'

0 comments on commit d24de79

Please sign in to comment.