|
| 1 | +name: Mono Engine deploy |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + paths: |
| 7 | + - ".github/workflows/mono-engine-deploy.yml" |
| 8 | + - "src/**" |
| 9 | + - "config/**" |
| 10 | + - "Cargo.toml" |
| 11 | + - "Cargo.lock" |
| 12 | + - "Dockerfile" |
| 13 | + - ".dockerignore" |
| 14 | + |
| 15 | +env: |
| 16 | + REPOSITORY: mega2/mega2 |
| 17 | + IMAGE_TAG_BASE: latest |
| 18 | + HARBOR_REGISTRY: registry.xuanwu.openatom.cn |
| 19 | + |
| 20 | +# actions: write is required for docker buildx --cache-{from,to} type=gha. |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + actions: write |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 27 | + cancel-in-progress: true |
| 28 | + |
| 29 | +jobs: |
| 30 | + build-and-push: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + timeout-minutes: 60 |
| 33 | + |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - name: Set up Docker Buildx |
| 38 | + uses: docker/setup-buildx-action@v3 |
| 39 | + |
| 40 | + # Expose ACTIONS_RUNTIME_TOKEN / ACTIONS_RESULTS_URL for raw |
| 41 | + # `docker buildx --cache-{from,to} type=gha` in the build step. |
| 42 | + - name: Expose GitHub Actions runtime env |
| 43 | + uses: crazy-max/ghaction-github-runtime@v3 |
| 44 | + |
| 45 | + - name: Login to Harbor |
| 46 | + uses: docker/login-action@v3 |
| 47 | + with: |
| 48 | + registry: ${{ env.HARBOR_REGISTRY }} |
| 49 | + username: ${{ secrets.HARBOR_USERNAME }} |
| 50 | + password: ${{ secrets.HARBOR_PASSWORD }} |
| 51 | + |
| 52 | + - name: Build & push image |
| 53 | + run: | |
| 54 | + set -euo pipefail |
| 55 | +
|
| 56 | + HARBOR_BASE="${{ env.HARBOR_REGISTRY }}/${{ env.REPOSITORY }}" |
| 57 | + SHORT_SHA="${GITHUB_SHA:0:7}" |
| 58 | + TAG_BASE="${{ env.IMAGE_TAG_BASE }}" |
| 59 | + CACHE_SCOPE="mega2-amd64" |
| 60 | +
|
| 61 | + echo "HARBOR_IMAGE=$HARBOR_BASE:$TAG_BASE" |
| 62 | + echo "HARBOR_SHA=$HARBOR_BASE:$SHORT_SHA" |
| 63 | + echo "CACHE_SCOPE=$CACHE_SCOPE" |
| 64 | +
|
| 65 | + docker buildx build \ |
| 66 | + --cache-from type=gha,scope=$CACHE_SCOPE \ |
| 67 | + --cache-to type=gha,mode=max,scope=$CACHE_SCOPE \ |
| 68 | + --provenance=false \ |
| 69 | + --sbom=false \ |
| 70 | + -f ./Dockerfile \ |
| 71 | + -t "$HARBOR_BASE:$TAG_BASE" \ |
| 72 | + -t "$HARBOR_BASE:$SHORT_SHA" \ |
| 73 | + --push . |
0 commit comments