|
| 1 | +name: Publish mobile image to GHCR |
| 2 | + |
| 3 | +# Build the QuantDinger mobile H5/PWA bundle and publish a multi-arch nginx |
| 4 | +# image to GitHub Container Registry. Version tags also create a GitHub Release |
| 5 | +# with a dist.tar.gz static bundle attached. |
| 6 | +# |
| 7 | +# Consumed as: |
| 8 | +# ghcr.io/<owner>/quantdinger-mobile:<tag> |
| 9 | +# |
| 10 | +# Triggers: |
| 11 | +# - push of a version tag matching `v*` (e.g. v4.0.1) -> semver + latest |
| 12 | +# tags pushed AND a GitHub Release published |
| 13 | +# - manual workflow_dispatch -> short-SHA tag only, no Release |
| 14 | +# |
| 15 | +# First-time setup: after the first successful run, visit |
| 16 | +# https://github.com/users/<owner>/packages/container/quantdinger-mobile/settings |
| 17 | +# and set the package visibility to public if anonymous `docker pull` is desired. |
| 18 | + |
| 19 | +on: |
| 20 | + push: |
| 21 | + tags: |
| 22 | + - 'v*' |
| 23 | + workflow_dispatch: |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: release-mobile-${{ github.ref }} |
| 27 | + cancel-in-progress: true |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: write |
| 31 | + packages: write |
| 32 | + |
| 33 | +jobs: |
| 34 | + publish: |
| 35 | + name: Build & push mobile image |
| 36 | + runs-on: ubuntu-latest |
| 37 | + steps: |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Set up QEMU |
| 42 | + uses: docker/setup-qemu-action@v3 |
| 43 | + |
| 44 | + - name: Set up Docker Buildx |
| 45 | + uses: docker/setup-buildx-action@v3 |
| 46 | + |
| 47 | + - name: Log in to GHCR |
| 48 | + uses: docker/login-action@v3 |
| 49 | + with: |
| 50 | + registry: ghcr.io |
| 51 | + username: ${{ github.actor }} |
| 52 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + |
| 54 | + - name: Extract image metadata |
| 55 | + id: meta |
| 56 | + uses: docker/metadata-action@v5 |
| 57 | + with: |
| 58 | + images: ghcr.io/${{ github.repository_owner }}/quantdinger-mobile |
| 59 | + tags: | |
| 60 | + type=ref,event=tag |
| 61 | + type=semver,pattern={{version}} |
| 62 | + type=semver,pattern={{major}}.{{minor}} |
| 63 | + type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} |
| 64 | + type=sha,format=short |
| 65 | +
|
| 66 | + - name: Build and push mobile web image |
| 67 | + uses: docker/build-push-action@v6 |
| 68 | + with: |
| 69 | + context: . |
| 70 | + file: ./Dockerfile |
| 71 | + platforms: linux/amd64,linux/arm64 |
| 72 | + push: true |
| 73 | + tags: ${{ steps.meta.outputs.tags }} |
| 74 | + labels: ${{ steps.meta.outputs.labels }} |
| 75 | + cache-from: type=gha,scope=mobile |
| 76 | + cache-to: type=gha,mode=max,scope=mobile |
| 77 | + build-args: | |
| 78 | + APP_VERSION=${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || '' }} |
| 79 | + GIT_TAG=${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || '' }} |
| 80 | + provenance: false |
| 81 | + |
| 82 | + - name: Extract dist tarball from just-pushed image |
| 83 | + if: startsWith(github.ref, 'refs/tags/v') |
| 84 | + env: |
| 85 | + IMAGE: ghcr.io/${{ github.repository_owner }}/quantdinger-mobile:${{ github.ref_name }} |
| 86 | + run: | |
| 87 | + set -euo pipefail |
| 88 | + docker pull --platform linux/amd64 "$IMAGE" |
| 89 | + CID=$(docker create --platform linux/amd64 "$IMAGE") |
| 90 | + mkdir -p _dist |
| 91 | + docker cp "$CID:/usr/share/nginx/html/." _dist/ |
| 92 | + docker rm "$CID" > /dev/null |
| 93 | + tar -czf dist.tar.gz -C _dist . |
| 94 | + sha256sum dist.tar.gz | tee dist.tar.gz.sha256 |
| 95 | + du -h dist.tar.gz |
| 96 | +
|
| 97 | + - name: Create or update GitHub Release |
| 98 | + if: startsWith(github.ref, 'refs/tags/v') |
| 99 | + uses: softprops/action-gh-release@v2 |
| 100 | + with: |
| 101 | + generate_release_notes: true |
| 102 | + append_body: true |
| 103 | + files: | |
| 104 | + dist.tar.gz |
| 105 | + dist.tar.gz.sha256 |
| 106 | + body: | |
| 107 | + ## QuantDinger Mobile ${{ github.ref_name }} |
| 108 | +
|
| 109 | + **Docker image (multi-arch, amd64 + arm64):** |
| 110 | +
|
| 111 | + ```bash |
| 112 | + docker pull ghcr.io/${{ github.repository_owner }}/quantdinger-mobile:${{ github.ref_name }} |
| 113 | + ``` |
| 114 | +
|
| 115 | + Example: |
| 116 | +
|
| 117 | + ```bash |
| 118 | + docker run -d --name quantdinger-mobile -p 8081:80 ghcr.io/${{ github.repository_owner }}/quantdinger-mobile:${{ github.ref_name }} |
| 119 | + ``` |
| 120 | +
|
| 121 | + **Static bundle:** `dist.tar.gz` can be extracted into any nginx/static host as `/usr/share/nginx/html/` (verify with `dist.tar.gz.sha256`). |
| 122 | +
|
| 123 | + --- |
0 commit comments