-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (105 loc) · 4.53 KB
/
Copy pathdocker.yml
File metadata and controls
119 lines (105 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Docker Build & Publish
on:
push:
branches: ["**"]
tags: ["v*"]
paths-ignore:
- "**/*.md"
- "**/*.rst"
- "docs/**"
- ".github/ISSUE_TEMPLATE/**"
workflow_dispatch: {}
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }} # may include uppercase (we'll normalize)
# Flip this to "true" if you want multi-arch on all branches
MULTIARCH_ON_BRANCHES: "false"
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
IS_MAIN: ${{ github.ref == 'refs/heads/main' }}
IS_TAG: ${{ startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
# Only set up QEMU when we actually need arm64 (main or tag builds)
- name: Set up QEMU (for arm64)
if: env.IS_MAIN == 'true' || env.IS_TAG == 'true' || env.MULTIARCH_ON_BRANCHES == 'true'
uses: docker/setup-qemu-action@v3
- name: Normalize image name to lowercase
id: repo
run: |
echo "image_name_lc=$(echo '${{ env.IMAGE_NAME }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- name: Derive tags
id: meta
run: |
REF="${GITHUB_REF#refs/}"
SHA_TAG=${GITHUB_SHA::12}
echo "sha_tag=${SHA_TAG}" >> "$GITHUB_OUTPUT"
if [[ "$REF" == tags/v* ]]; then
V="${REF#tags/v}"
echo "version_tag=${V}" >> "$GITHUB_OUTPUT"
fi
if [[ "$REF" == heads/main ]]; then
echo "latest_tag=latest" >> "$GITHUB_OUTPUT"
fi
# Fast path for branches: single-arch build, cache, don't push
- name: Build (branch) — fast single-arch, no push
if: env.IS_MAIN != 'true' && env.IS_TAG != 'true' && env.MULTIARCH_ON_BRANCHES != 'true'
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: false
load: true # so we can run the smoke test
platforms: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
tags: |
${{ env.REGISTRY }}/${{ steps.repo.outputs.image_name_lc }}:${{ steps.meta.outputs.sha_tag }}
# Publish path for main/tags: multi-arch build + push (with cache)
- name: Build & push (multi-arch)
if: env.IS_MAIN == 'true' || env.IS_TAG == 'true' || env.MULTIARCH_ON_BRANCHES == 'true'
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
tags: |
${{ env.REGISTRY }}/${{ steps.repo.outputs.image_name_lc }}:${{ steps.meta.outputs.sha_tag }}
${{ steps.meta.outputs.version_tag && format('{0}/{1}:{2}', env.REGISTRY, steps.repo.outputs.image_name_lc, steps.meta.outputs.version_tag) || '' }}
${{ steps.meta.outputs.latest_tag && format('{0}/{1}:{2}', env.REGISTRY, steps.repo.outputs.image_name_lc, steps.meta.outputs.latest_tag) || '' }}
# Smoke test: use the local image for branch builds, or pull the pushed one for main/tags
- name: Smoke test (branch image)
if: env.IS_MAIN != 'true' && env.IS_TAG != 'true' && env.MULTIARCH_ON_BRANCHES != 'true'
run: |
IMAGE="${{ env.REGISTRY }}/${{ steps.repo.outputs.image_name_lc }}:${{ steps.meta.outputs.sha_tag }}"
echo "Smoke testing local image ${IMAGE}"
docker run --rm "$IMAGE" python -c "import exosuit_python, sys; print('✅ import ok:', getattr(exosuit_python,'__version__','?'), 'on', sys.version)"
- name: Smoke test (pushed image)
if: env.IS_MAIN == 'true' || env.IS_TAG == 'true' || env.MULTIARCH_ON_BRANCHES == 'true'
run: |
IMAGE="${{ env.REGISTRY }}/${{ steps.repo.outputs.image_name_lc }}:${{ steps.meta.outputs.sha_tag }}"
echo "Smoke testing pushed image ${IMAGE}"
docker pull "$IMAGE"
docker run --rm "$IMAGE" python -c "import exosuit_python, sys; print('✅ import ok:', getattr(exosuit_python,'__version__','?'), 'on', sys.version)"