Skip to content

CI/CD with Docker

CI/CD with Docker #936

Workflow file for this run

name: CI/CD with Docker
on:
schedule:
- cron: '0 0 */3 * *' # Run every 3 days at midnight UTC
push:
branches: [ main ]
pull_request:
branches: [ main ] # Added to run checks on PRs
# Limit concurrent runs of this workflow
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true # Cancels in-progress runs when a new workflow is triggered
permissions:
contents: read
pages: write
id-token: write
env:
TAG_NAME: ${{ github.sha }}
DOCKER_BUILDKIT: 1 # Enable BuildKit for faster builds
jobs:
build:
name: Build for GitHub Pages
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 1 # Shallow clone for faster checkout
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# - name: Cache Docker layers
# uses: actions/cache@v3
# with:
# path: /tmp/.buildx-cache
# key: ${{ runner.os }}-buildx-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-buildx-
- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.OS }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-npm-
- name: Cache Playwright browsers
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/ms-playwright
key: ${{ runner.OS }}-playwright-${{ hashFiles('**/package-lock.json') }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
load: true
tags: lojban:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
build-args: |
BUILDKIT_INLINE_CACHE=1
NODE_ENV=production
# - name: Move cache
# run: |
# rm -rf /tmp/.buildx-cache
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Run Docker container
run: |
docker run --rm -v /output:/app/src/out1 \
-v ${{ github.workspace }}/data/config:/app/src/config:Z \
-v ${{ github.workspace }}/ms-playwright:/ms-playwright:Z \
-v ${{ github.workspace }}/node_modules:/app/src/node_modules:Z \
-v ${{ github.workspace }}/data/pages:/app/src/md_pages:Z \
-v ${{ github.workspace }}/data/assets:/app/src/public/assets:Z \
-v ${{ github.workspace }}/data/DNS:/app/service/DNS:Z \
-v ${{ github.workspace }}/src:/app/src:Z \
-e GOOGLE_LOJBAN_CORPUS_DOC_ID=${{ secrets.GOOGLE_LOJBAN_CORPUS_DOC_ID }} \
-e GOOGLE_READONLY_API_KEY=${{ secrets.GOOGLE_READONLY_API_KEY }} \
-e CI=true \
lojban:latest \
sh -c "npm ci --prefer-offline --force && npx playwright install chromium --with-deps && npm run cicd"
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: /output/
retention-days: 1
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4