|
| 1 | +name: Docker Package |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - main |
| 8 | + tags: |
| 9 | + - "v*.*.*" |
| 10 | + paths: |
| 11 | + - Dockerfile |
| 12 | + - package.json |
| 13 | + - pnpm-lock.yaml |
| 14 | + - src/** |
| 15 | + - public/** |
| 16 | + - nitro.config.ts |
| 17 | + - .github/workflows/docker-package.yml |
| 18 | + workflow_dispatch: |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + packages: write |
| 23 | + |
| 24 | +concurrency: |
| 25 | + group: docker-package-${{ github.ref }} |
| 26 | + cancel-in-progress: false |
| 27 | + |
| 28 | +jobs: |
| 29 | + publish-ghcr: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Checkout |
| 34 | + uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Set up Node.js |
| 37 | + uses: actions/setup-node@v4 |
| 38 | + with: |
| 39 | + node-version: 24 |
| 40 | + |
| 41 | + - name: Resolve image and package version |
| 42 | + id: vars |
| 43 | + shell: bash |
| 44 | + run: | |
| 45 | + set -euo pipefail |
| 46 | + OWNER="$(echo "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')" |
| 47 | + IMAGE="$(basename "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')" |
| 48 | + VERSION="$(node -p "require('./package.json').version")" |
| 49 | + VERSION="$(echo "$VERSION" | xargs)" |
| 50 | +
|
| 51 | + if [ -z "$VERSION" ]; then |
| 52 | + echo "::error::package.json version is empty." |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then |
| 57 | + echo "::error::Invalid package.json version: '$VERSION'" |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | +
|
| 61 | + echo "owner=$OWNER" >> "$GITHUB_OUTPUT" |
| 62 | + echo "image=$IMAGE" >> "$GITHUB_OUTPUT" |
| 63 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 64 | + echo "version_tag=v${VERSION}" >> "$GITHUB_OUTPUT" |
| 65 | +
|
| 66 | + - name: Set up QEMU |
| 67 | + uses: docker/setup-qemu-action@v3 |
| 68 | + |
| 69 | + - name: Set up Docker Buildx |
| 70 | + uses: docker/setup-buildx-action@v3 |
| 71 | + |
| 72 | + - name: Log in to GitHub Container Registry |
| 73 | + uses: docker/login-action@v3 |
| 74 | + with: |
| 75 | + registry: ghcr.io |
| 76 | + username: ${{ github.actor }} |
| 77 | + password: ${{ secrets.TOKEN_GITHUB }} |
| 78 | + |
| 79 | + - name: Generate image metadata |
| 80 | + id: meta |
| 81 | + uses: docker/metadata-action@v5 |
| 82 | + with: |
| 83 | + images: ghcr.io/${{ steps.vars.outputs.owner }}/${{ steps.vars.outputs.image }} |
| 84 | + tags: | |
| 85 | + type=raw,value=latest,enable={{is_default_branch}} |
| 86 | + type=raw,value=${{ steps.vars.outputs.version_tag }} |
| 87 | + type=raw,value=${{ steps.vars.outputs.version }} |
| 88 | + type=ref,event=tag |
| 89 | + type=sha,format=short |
| 90 | +
|
| 91 | + - name: Build and push image package |
| 92 | + uses: docker/build-push-action@v6 |
| 93 | + with: |
| 94 | + context: . |
| 95 | + file: ./Dockerfile |
| 96 | + push: true |
| 97 | + tags: ${{ steps.meta.outputs.tags }} |
| 98 | + labels: ${{ steps.meta.outputs.labels }} |
| 99 | + build-args: | |
| 100 | + RUN_TESTS=false |
| 101 | + cache-from: type=gha |
| 102 | + cache-to: type=gha,mode=max |
0 commit comments