Skip to content

Commit

Permalink
Build Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
roelofr committed Nov 23, 2023
1 parent 3884edc commit 857604f
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 147 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.nuxt/
node_modules/
88 changes: 71 additions & 17 deletions .github/workflows/verify-and-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Verify and Build
name: Verify, Build and Package

on:
push:
Expand All @@ -9,6 +9,10 @@ on:

pull_request:

env:
DOCKER_REGISTRY: ghcr.io
DOCKER_IMAGE_NAME: ${{ github.repository }}

jobs:
test-and-build:
name: Build application
Expand All @@ -25,40 +29,90 @@ jobs:
cache: 'npm'

- name: Install dependencies
run: npm ci
run: npm clean-install

- name: Run linter
run: npm run lint

- name: Build application
- name: Generate static application
run: npm run generate

- name: Upload application
uses: actions/upload-artifact@v3
with:
name: output
name: static
path: .output/public/
if-no-files-found: error

- name: Update application version
if: startsWith(github.ref, 'refs/tags/v')
run: |
# Load version from Git
npm version --allow-same-version --no-git-tag-version from-git
- name: Generate SSR application
run: npm run build

- name: Upload application
uses: actions/upload-artifact@v3
with:
name: ssr
path: .output/
if-no-files-found: error

# Set as env
export NODE_PKG_VERSION=$( jq -r '.version' package.json )
echo "NODE_PKG_VERSION=${NODE_PKG_VERSION}" >> $GITHUB_ENV
create-release:
name: Create Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')

needs:
- test-and-build

steps:
- name: Download static application
uses: actions/download-artifact@v3
with:
name: static
path: static

- name: Bundle application
if: startsWith(github.ref, 'refs/tags/v')
working-directory: .output/public
run: tar -czf ../../minisites.tgz ./*
working-directory: static
run: tar -czf ../minisites.tgz ./*

- name: Release
- name: Create Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
with:
name: Version ${{ env.NODE_PKG_VERSION }}
files: minisites.tgz
generate_release_notes: true

create-docker-image:
name: Create Docker Image
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main'

needs:
- test-and-build

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Download application
uses: actions/download-artifact@v3
with:
name: ssr
path: .output

- name: Determine version tag
id: version
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:lts-alpine

# Copy app
COPY .output /opt/app

# Expose proper port
ENV NITRO_PORT=3000
ENV NITRO_HOST=0.0.0.0

EXPOSE 3000

# Update entrypoint
ENTRYPOINT [ "node", "/opt/app/server/index.mjs" ]
Loading

0 comments on commit 857604f

Please sign in to comment.