Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add production ready nginx docker image #20

Merged
merged 22 commits into from May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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/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;'