diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5e49d13 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +**/node_modules +**/dist +.git +.gitignore +**/Dockerfile +**/docker-compose.yml +**/.env +**/secrets/ \ No newline at end of file diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..a41ad0b --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,75 @@ +name: Create and publish a Docker image + +on: push + +env: + REGISTRY: ghcr.io + ANGULAR_IMAGE: quanted/vb-angular + NGINX_IMAGE: quanted/vb-nginx + +jobs: + build-angular: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.ANGULAR_IMAGE }} + + - name: Build and push Cyanweb Angular/Node Docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + build-args: env=kube + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + build-nginx: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + needs: build-angular + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.NGINX_IMAGE }} + + - name: Build and push Cyanweb Nginx Docker image + uses: docker/build-push-action@v2 + with: + context: . + file: docker/nginx/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: config=nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9f30231 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM node:lts-alpine + +# Build-time variables (see package.json) +ARG env=standalone + +# Env vars for angular unit tests and bypassing angular CLI install prompt: +ENV CHROME_BIN=/usr/bin/chromium-browser \ + CHROME_PATH=/usr/lib/chromium/ \ + NG_CLI_ANALYTICS=false + +ENV APP_USER=www-data + +COPY . /app + +# COPY docker/ /docker + +WORKDIR /app + +RUN apk update && \ + apk upgrade && \ + apk add chromium + +# RUN npm install --force +RUN npm install +RUN npm run build:$env + +RUN adduser -S $APP_USER -G $APP_USER + +# RUN chown -R $APP_USER:$APP_USER /app /docker +RUN chown -R $APP_USER:$APP_USER /app + +# Runs as non-root user "www-data" +USER $APP_USER \ No newline at end of file diff --git a/package.json b/package.json index 9a43d69..d079564 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,10 @@ "ng": "ng", "start": "ng serve", "build": "ng build", - "build-kube": "ng build --baseHref=/vb --outputPath=../vb_django/vb_django/static", + "build-kube": "ng build --baseHref=/vb --q=../vb_django/vb_django/static", + "build:orig": "ng build --baseHref=/vb", + "build:standalone": "ng build --prod --outputPath=dist", + "build:kube": "ng build --prod --baseHref=/vbweb/ --outputPath=dist/vbweb --outputHashing=bundles", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e"