Update docker-image.yml
This commit is contained in:
68
.github/workflows/docker-image.yml
vendored
68
.github/workflows/docker-image.yml
vendored
@@ -16,38 +16,42 @@ permissions:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Determine Image Tag
|
||||
id: image_tag
|
||||
run: |
|
||||
if [ "${{ github.ref_type }}" == "tag" ]; then
|
||||
IMAGE_NAME="ghcr.io/chocomeow/vocard:${{ github.ref_name }}"
|
||||
elif [ "${{ github.ref }}" == "refs/heads/beta" ]; then
|
||||
IMAGE_NAME="ghcr.io/chocomeow/vocard:beta"
|
||||
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
||||
IMAGE_NAME="ghcr.io/chocomeow/vocard:latest"
|
||||
else
|
||||
echo "Error: Triggered on an unexpected ref: ${{ github.ref }}"
|
||||
exit 1
|
||||
fi
|
||||
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
|
||||
echo "Set image name to: ${IMAGE_NAME}"
|
||||
|
||||
- name: Build the Docker image
|
||||
run: |
|
||||
echo "Building image: ${{ env.IMAGE_NAME }}"
|
||||
docker build . --file Dockerfile --tag ${{ env.IMAGE_NAME }}
|
||||
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to GitHub Docker Registry
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
||||
|
||||
- name: Push the Docker image
|
||||
run: |
|
||||
echo "Pushing image: ${{ env.IMAGE_NAME }}"
|
||||
docker push ${{ env.IMAGE_NAME }}
|
||||
echo "Successfully pushed ${{ env.IMAGE_NAME }}"
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ghcr.io/chocomeow/vocard
|
||||
tags: |
|
||||
# For version tags (v1.2.3)
|
||||
type=ref,event=tag
|
||||
# For main branch
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
# For beta branch
|
||||
type=raw,value=beta,enable=${{ github.ref == 'refs/heads/beta' }}
|
||||
flavor: |
|
||||
latest=false
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
Reference in New Issue
Block a user