ci(prod): update image build workflow to push to Forgejo registry with commit SHA
build-prod / build-push (push) Canceled after 0s
build-prod / build-push (push) Canceled after 0s
This commit is contained in:
@@ -9,28 +9,44 @@ jobs:
|
|||||||
runs-on: docker
|
runs-on: docker
|
||||||
permissions:
|
permissions:
|
||||||
packages: write
|
packages: write
|
||||||
|
contents: read
|
||||||
|
env:
|
||||||
|
REGISTRY: forgejo.riotpiao.com
|
||||||
|
IMAGE_NAME: rock/kmsvc-manage
|
||||||
steps:
|
steps:
|
||||||
- name: install buildx and git
|
- name: Checkout code
|
||||||
run: apk add --no-cache docker git
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
- name: Get commit short SHA
|
||||||
|
id: short_sha
|
||||||
|
run: echo "sha=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Build and push image (commit SHA + latest)
|
- name: Log in to Forgejo Container Registry
|
||||||
run: |
|
uses: docker/login-action@v3
|
||||||
COMMIT_SHA=${{ github.sha }}
|
with:
|
||||||
SHORT_SHA=${COMMIT_SHA:0:7}
|
registry: ${{ env.REGISTRY }}
|
||||||
IMAGE_NAME="forgejo.riotpiao.com/rock/kmsvc-manage"
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
docker build \
|
|
||||||
-t ${IMAGE_NAME}:${SHORT_SHA} \
|
- name: Extract metadata (tags, labels)
|
||||||
-t ${IMAGE_NAME}:latest \
|
id: meta
|
||||||
.
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
# For now, tag locally. When registry auth is configured:
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
# docker push ${IMAGE_NAME}:${SHORT_SHA}
|
tags: |
|
||||||
# docker push ${IMAGE_NAME}:latest
|
type=raw,value=${{ steps.short_sha.outputs.sha }}
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
echo "Built image: ${IMAGE_NAME}:${SHORT_SHA} and ${IMAGE_NAME}:latest"
|
|
||||||
|
- name: Build and push image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|||||||
Reference in New Issue
Block a user