Build Docker images #27
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Verify, Build and Package | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- v* | |
pull_request: | |
env: | |
DOCKER_REGISTRY: ghcr.io | |
DOCKER_IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
test-and-build: | |
name: Build application | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup NodeJS | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 'lts/*' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm clean-install | |
- name: Run linter | |
run: npm run lint | |
- name: Generate static application | |
run: npm run generate | |
- name: Upload application | |
uses: actions/upload-artifact@v3 | |
with: | |
name: static | |
path: .output/public/ | |
if-no-files-found: error | |
- 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 | |
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 | |
working-directory: static | |
run: tar -czf ../minisites.tgz ./* | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
if: startsWith(github.ref, 'refs/tags/v') | |
with: | |
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 }} |