Skip to content

Commit 00260cf

Browse files
authored
Update Docker build workflow for improved steps
1 parent e80bad5 commit 00260cf

1 file changed

Lines changed: 27 additions & 22 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,33 @@ jobs:
55
build:
66
runs-on: ubuntu-latest
77
steps:
8-
# Step 1: Checkout the repository code
9-
- name: Checkout repository
10-
uses: actions/checkout@v3
8+
- name: Checkout repository
9+
uses: actions/checkout@v2
1110

12-
# Step 2: Set up Docker Buildx (for multi-platform builds if needed)
13-
- name: Set up Docker Buildx
14-
uses: docker/setup-buildx-action@v2
11+
# Login against a Docker registry except on PR
12+
# https://github.com/docker/login-action
13+
- name: Log into registry ${{ env.REGISTRY }}
14+
if: github.event_name != 'pull_request'
15+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
16+
with:
17+
registry: ${{ env.REGISTRY }}
18+
username: ${{ github.actor }}
19+
password: ${{ secrets.GITHUB_TOKEN }}
1520

16-
# Step 3: Log in to GitHub Container Registry
17-
- name: Log in to GHCR
18-
uses: docker/login-action@v2
19-
with:
20-
registry: ghcr.io
21-
username: ${{ github.actor }}
22-
password: ${{ secrets.GITHUB_TOKEN }}
21+
# Extract metadata (tags, labels) for Docker
22+
# https://github.com/docker/metadata-action
23+
- name: Extract Docker metadata
24+
id: meta
25+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
26+
with:
27+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
2328

24-
# Step 4: Build the Docker image
25-
- name: Build Docker image
26-
run: |
27-
docker build -t ghcr.io/${{ github.repository_owner }}/strfry:latest .
28-
29-
# Step 5: Push the Docker image to GHCR
30-
- name: Push Docker image to GHCR
31-
run: |
32-
docker push ghcr.io/${{ github.repository_owner }}/strfry:latest
29+
# Build and push Docker image with Buildx (don't push on PR)
30+
# https://github.com/docker/build-push-action
31+
- name: Build and push Docker image
32+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
33+
with:
34+
context: .
35+
push: ${{ github.event_name != 'pull_request' }}
36+
tags: ${{ steps.meta.outputs.tags }}
37+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)