Update docker-image.yml
This commit is contained in:
62
.github/workflows/docker-image.yml
vendored
62
.github/workflows/docker-image.yml
vendored
@@ -16,38 +16,42 @@ permissions:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Determine Image Tag
|
- name: Set up Docker Buildx
|
||||||
id: image_tag
|
uses: docker/setup-buildx-action@v3
|
||||||
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: Log in to GitHub Docker Registry
|
- name: Log in to GitHub Docker Registry
|
||||||
env:
|
uses: docker/login-action@v3
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
with:
|
||||||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Push the Docker image
|
- name: Extract metadata
|
||||||
run: |
|
id: meta
|
||||||
echo "Pushing image: ${{ env.IMAGE_NAME }}"
|
uses: docker/metadata-action@v5
|
||||||
docker push ${{ env.IMAGE_NAME }}
|
with:
|
||||||
echo "Successfully pushed ${{ env.IMAGE_NAME }}"
|
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