Skip to content

Commit aa8ada8

Browse files
authored
Bug/fix docker build not getting directory packages props (#446)
Fix docker build & Attempt to reuse docker build on deploy and pr status check
1 parent 85c7d75 commit aa8ada8

4 files changed

Lines changed: 107 additions & 62 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Docker Build (Reusable)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
push:
7+
description: 'Push image to Docker Hub and attest it'
8+
type: boolean
9+
default: false
10+
version:
11+
description: 'Version tag for the image'
12+
type: string
13+
default: ''
14+
secrets:
15+
DOCKERHUB_TOKEN:
16+
required: false
17+
18+
permissions:
19+
id-token: write
20+
attestations: write
21+
22+
jobs:
23+
build:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
id-token: write
28+
attestations: write
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v7
32+
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v4
35+
36+
# Only log in when we intend to push (keeps secrets out of PR builds)
37+
- name: Log in to Docker Hub
38+
if: inputs.push
39+
uses: docker/login-action@v4
40+
with:
41+
username: tragiccode
42+
password: ${{ secrets.DOCKERHUB_TOKEN }}
43+
44+
- name: Extract metadata (tags, labels) for Docker
45+
id: meta
46+
uses: docker/metadata-action@v6
47+
with:
48+
images: tragiccode/busly-cli
49+
tags: |
50+
${{ inputs.version }}
51+
latest
52+
53+
- name: Build (and maybe push) Docker image
54+
id: push
55+
uses: docker/build-push-action@v7
56+
with:
57+
context: .
58+
file: ./src/BuslyCLI.Console/Dockerfile
59+
build-args: |
60+
APP_VERSION=${{ inputs.version }}
61+
push: ${{ inputs.push }}
62+
tags: ${{ inputs.push && steps.meta.outputs.tags || '' }}
63+
labels: ${{ steps.meta.outputs.labels }}
64+
65+
- name: Generate artifact attestation
66+
if: inputs.push
67+
uses: actions/attest-build-provenance@v4
68+
with:
69+
subject-name: index.docker.io/tragiccode/busly-cli
70+
subject-digest: ${{ steps.push.outputs.digest }}
71+
push-to-registry: true

‎.github/workflows/docker_deploy.yml‎

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,27 @@ on:
44
release:
55
types: [published]
66

7-
permissions:
8-
id-token: write
9-
attestations: write
10-
117
jobs:
12-
build:
8+
version:
139
runs-on: ubuntu-latest
14-
10+
outputs:
11+
version: ${{ steps.version.outputs.version }}
1512
steps:
16-
- name: Checkout
17-
uses: actions/checkout@v7
18-
19-
- name: Extract version (without v)
20-
id: version
13+
- id: version
2114
run: |
22-
if [ "${{ github.event_name }}" = "release" ]; then
23-
# Extract version from release tag (remove any 'v' prefix)
24-
VERSION="${{ github.event.release.tag_name }}"
25-
VERSION=${VERSION#v} # Remove 'v' prefix if present
26-
else
27-
VERSION="${{ github.event.inputs.version }}"
28-
VERSION=${VERSION#v} # Remove 'v' prefix if present
29-
fi
30-
31-
echo "version=$VERSION" >> $GITHUB_OUTPUT
32-
echo "Syncing version: $VERSION"
33-
34-
- name: Set up Docker Buildx
35-
uses: docker/setup-buildx-action@v4
36-
37-
- name: Log in to Docker Hub
38-
uses: docker/login-action@v4
39-
with:
40-
username: tragiccode
41-
password: ${{ secrets.DOCKERHUB_TOKEN }}
42-
43-
# Revisit this. We should probably be triggering this off of a tag event.
44-
# Which would automatically tag the image with the version and latest and allow us to remove
45-
# the manual 'tags' property below
46-
- name: Extract metadata (tags, labels) for Docker
47-
id: meta
48-
uses: docker/metadata-action@v6
49-
with:
50-
images: tragiccode/busly-cli
51-
tags: |
52-
${{ steps.version.outputs.version }}
53-
latest
54-
55-
- name: Build and push Docker image
56-
id: push
57-
uses: docker/build-push-action@v7
58-
with:
59-
context: .
60-
file: ./src/BuslyCLI.Console/Dockerfile
61-
build-args: |
62-
APP_VERSION=${{ steps.version.outputs.version }}
63-
push: true
64-
tags: ${{ steps.meta.outputs.tags }}
65-
labels: ${{ steps.meta.outputs.labels }}
66-
67-
- name: Generate artifact attestation
68-
uses: actions/attest-build-provenance@v4
69-
with:
70-
subject-name: index.docker.io/tragiccode/busly-cli
71-
subject-digest: ${{ steps.push.outputs.digest }}
72-
push-to-registry: true
15+
VERSION="${{ github.event.release.tag_name }}"
16+
VERSION=${VERSION#v}
17+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
18+
19+
docker:
20+
needs: version
21+
uses: ./.github/workflows/docker_build_or_deploy.yml
22+
# permissions:
23+
# contents: read
24+
# id-token: write
25+
# attestations: write
26+
with:
27+
push: true
28+
version: ${{ needs.version.outputs.version }}
29+
secrets:
30+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Pull Request Docker Build
2+
3+
on:
4+
pull_request:
5+
# Can't do this because i don't have a pr number...
6+
# schedule:
7+
# # Runs every night at 2 AM UTC. This is to detect flakey builds
8+
# - cron: "0 2 * * *"
9+
10+
jobs:
11+
docker:
12+
uses: ./.github/workflows/docker_build_or_deploy.yml
13+
with:
14+
push: false
15+
version: 1.0.0-pr.${{ github.event.number }}.${{ github.sha }}

‎src/BuslyCLI.Console/Dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ARG APP_VERSION=0.1.0
55
WORKDIR /src
66

77
COPY Directory.Build.props ./
8+
COPY Directory.Packages.props ./
89

910
# Copy project file and restore dependencies (better layer caching)
1011
COPY src/BuslyCLI.Console/BuslyCLI.Console.csproj ./BuslyCLI.Console/

0 commit comments

Comments
 (0)