Skip to content

Commit 49406dd

Browse files
committed
Try a different approach to building the docker image in GitHub workflows
1 parent 2060a82 commit 49406dd

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
name: Build and Push Docker Image
21

32
on:
43
push:
@@ -53,3 +52,51 @@ jobs:
5352
*.labels=${{ steps.meta.outputs.labels }}
5453
push: true
5554

55+
name: Build and Push Docker Image
56+
57+
on:
58+
push:
59+
branches:
60+
- main
61+
paths:
62+
- 'build/dockerfile'
63+
- 'build/requirements.txt'
64+
- 'build/docker-compose.yml'
65+
- '.github/workflows/build.yml'
66+
67+
jobs:
68+
build-and-push:
69+
runs-on: ubuntu-latest
70+
permissions:
71+
contents: read
72+
packages: write
73+
env:
74+
IMAGE_NAME: ghcr.io/${{ github.repository }}
75+
76+
steps:
77+
- name: Checkout repository
78+
uses: actions/checkout@v4
79+
80+
- name: Lowercase the image name
81+
run: echo "IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV
82+
83+
- name: Log in to GitHub Container Registry
84+
uses: docker/login-action@v3
85+
with:
86+
registry: ghcr.io
87+
username: ${{ github.actor }}
88+
password: ${{ secrets.GITHUB_TOKEN }}
89+
90+
- name: Build Docker image with Compose
91+
run: docker compose -f build/docker-compose.yml build
92+
93+
- name: Tag Docker images
94+
run: |
95+
docker tag "$IMAGE_NAME:latest" "$IMAGE_NAME:latest"
96+
docker tag "$IMAGE_NAME:latest" "$IMAGE_NAME:git-${GITHUB_SHA::7}"
97+
98+
- name: Push Docker images
99+
run: |
100+
docker push "$IMAGE_NAME:latest"
101+
docker push "$IMAGE_NAME:git-${GITHUB_SHA::7}"
102+

0 commit comments

Comments
 (0)