Skip to content

Try a different approach to building the docker image in GitHub workf… #6

Try a different approach to building the docker image in GitHub workf…

Try a different approach to building the docker image in GitHub workf… #6

Check failure on line 1 in .github/workflows/build-docker-image.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build-docker-image.yml

Invalid workflow file

(Line: 57, Col: 1): 'on' is already defined, (Line: 67, Col: 1): 'jobs' is already defined
on:
push:
branches:
- main
paths:
- 'build/dockerfile'
- 'build/requirements.txt'
- 'build/docker-compose.yml'
- '.github/workflows/build-docker-image.yml'
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set image name
run: echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
- name: Set Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push via Docker compose
uses: docker/bake-action@v5
with:
files: build/docker-compose.yml
targets: app
set: |
*.tags=${{ steps.meta.outputs.tags }}
*.labels=${{ steps.meta.outputs.labels }}
push: true
name: Build and Push Docker Image
on:
push:
branches:
- main
paths:
- 'build/dockerfile'
- 'build/requirements.txt'
- 'build/docker-compose.yml'
- '.github/workflows/build.yml'
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Lowercase the image name
run: echo "IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image with Compose
run: docker compose -f build/docker-compose.yml build
- name: Tag Docker images
run: |
docker tag "$IMAGE_NAME:latest" "$IMAGE_NAME:latest"
docker tag "$IMAGE_NAME:latest" "$IMAGE_NAME:git-${GITHUB_SHA::7}"
- name: Push Docker images
run: |
docker push "$IMAGE_NAME:latest"
docker push "$IMAGE_NAME:git-${GITHUB_SHA::7}"