-
Notifications
You must be signed in to change notification settings - Fork 78
169 lines (154 loc) · 7.26 KB
/
Copy pathpublish-dev-docker.yml
File metadata and controls
169 lines (154 loc) · 7.26 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Publish Dev Docker Image
on:
# Dev image publishing is driven entirely through the release flow
# (scripts/release.sh dispatches this workflow). The auto-build-on-proto-change
# push trigger was removed so a push to staging (e.g. a release merge or a
# sync-main force-push) no longer kicks off a duplicate dev image build.
workflow_dispatch:
inputs:
branch_name:
description: 'Branch to build from (default: staging). Used if no git_tag or commit_hash is provided, or for tagging context with commit_hash.'
required: false
type: string
default: 'staging'
commit_hash:
description: 'Specific commit SHA to build (optional). Overrides branch_name for checkout if provided. git_tag takes precedence over this.'
required: false
type: string
git_tag:
description: 'Specific Git tag to build (e.g., v1.6.0). Overrides commit_hash and branch_name for checkout.'
required: false
type: string
fast_build:
description: 'Enable fast build (linux/amd64 only) for development testing. Reduces build time by ~50%.'
required: false
type: boolean
default: false
# Cancel in-flight builds when a newer commit lands on staging
concurrency:
group: dev-docker-${{ github.ref }}
cancel-in-progress: true
jobs:
publish-staging-build:
name: Build and Publish Dev Docker Image to Dockerhub
runs-on: blacksmith-4vcpu-ubuntu-2404
steps:
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout code
id: checkout_code
uses: actions/checkout@v5
with:
fetch-depth: 0
# push event: github.ref is already correct (staging branch)
# workflow_dispatch: priority is git_tag > commit_hash > branch_name
ref: ${{ github.event_name == 'push' && github.ref || (github.event.inputs.git_tag && format('refs/tags/{0}', github.event.inputs.git_tag) || github.event.inputs.commit_hash || github.event.inputs.branch_name) }}
- name: Determine Tags and Build Args
id: vars
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
PRIMARY_DOCKER_TAG=""
BRANCH_FOR_CONTEXT=""
RELEASE_TAG_ARG=""
if [[ "${{ github.event_name }}" == "push" ]]; then
# Automatic build from staging push (PR merge)
BRANCH_NAME="${{ github.ref_name }}"
echo "Source: Push to ${BRANCH_NAME} (auto-build)"
PRIMARY_DOCKER_TAG="${BRANCH_NAME}-${SHORT_SHA}"
BRANCH_FOR_CONTEXT="$BRANCH_NAME"
RELEASE_TAG_ARG="${BRANCH_NAME}-${SHORT_SHA}"
elif [[ -n "${{ github.event.inputs.git_tag }}" ]]; then
echo "Source: Git Tag (${{ github.event.inputs.git_tag }})"
PRIMARY_DOCKER_TAG="${{ github.event.inputs.git_tag }}"
RELEASE_TAG_ARG="${{ github.event.inputs.git_tag }}"
elif [[ -n "${{ github.event.inputs.commit_hash }}" ]]; then
echo "Source: Commit SHA (${{ github.event.inputs.commit_hash }})"
RAW_BRANCH_CTX="${{ github.event.inputs.branch_name }}"
SANITIZED_BRANCH_CTX=$(echo "$RAW_BRANCH_CTX" | sed 's|/|-|g' | tr -cs 'a-zA-Z0-9.-_' '-' | sed 's/--\+/-/g' | sed 's/^-*//;s/-*$//')
if [[ -n "$SANITIZED_BRANCH_CTX" ]]; then
PRIMARY_DOCKER_TAG="$SANITIZED_BRANCH_CTX-$SHORT_SHA"
BRANCH_FOR_CONTEXT="$SANITIZED_BRANCH_CTX"
RELEASE_TAG_ARG="$SANITIZED_BRANCH_CTX-$SHORT_SHA"
else
PRIMARY_DOCKER_TAG="$SHORT_SHA"
RELEASE_TAG_ARG="$SHORT_SHA"
fi
else
# Source: Branch Name (no git_tag, no commit_hash)
RAW_BRANCH_NAME="${{ github.event.inputs.branch_name }}"
echo "Source: Branch ($RAW_BRANCH_NAME)"
SANITIZED_BRANCH_NAME=$(echo "$RAW_BRANCH_NAME" | sed 's|/|-|g' | tr -cs 'a-zA-Z0-9.-_' '-' | sed 's/--\+/-/g' | sed 's/^-*//;s/-*$//')
if [[ -n "$SANITIZED_BRANCH_NAME" ]]; then
PRIMARY_DOCKER_TAG="$SANITIZED_BRANCH_NAME-$SHORT_SHA"
BRANCH_FOR_CONTEXT="$SANITIZED_BRANCH_NAME"
RELEASE_TAG_ARG="$SANITIZED_BRANCH_NAME-$SHORT_SHA"
else
PRIMARY_DOCKER_TAG="unknown-$SHORT_SHA"
RELEASE_TAG_ARG="unknown-$SHORT_SHA"
fi
fi
echo "PRIMARY_DOCKER_TAG=${PRIMARY_DOCKER_TAG}" >> $GITHUB_OUTPUT
echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_OUTPUT
echo "BRANCH_FOR_CONTEXT=${BRANCH_FOR_CONTEXT}" >> $GITHUB_OUTPUT
echo "RELEASE_TAG_ARG=${RELEASE_TAG_ARG}" >> $GITHUB_OUTPUT
echo "Checked out commit short SHA: $SHORT_SHA"
echo "Primary Docker tag will be: $PRIMARY_DOCKER_TAG"
echo "Branch context for tagging (if any): $BRANCH_FOR_CONTEXT"
echo "RELEASE_TAG build argument will be: $RELEASE_TAG_ARG"
shell: bash
- name: Print Determined Tags and Args
run: |
echo "---- Debug: Values from vars step ----"
echo "Primary Docker Tag: ${{ steps.vars.outputs.PRIMARY_DOCKER_TAG }}"
echo "Short SHA: ${{ steps.vars.outputs.SHORT_SHA }}"
echo "Branch for Context: ${{ steps.vars.outputs.BRANCH_FOR_CONTEXT }}"
echo "Release Tag Arg for Build: ${{ steps.vars.outputs.RELEASE_TAG_ARG }}"
echo "---- End Debug ----"
shell: bash
# Automatic push builds use amd64-only (fast) since SDK CI runs on ubuntu.
# Manual dispatch respects the fast_build input.
- name: Resolve build platforms
id: platforms
run: |
if [[ "${{ github.event_name }}" == "push" || "${{ inputs.fast_build }}" == "true" ]]; then
echo "value=linux/amd64" >> $GITHUB_OUTPUT
echo "fast=true" >> $GITHUB_OUTPUT
echo "Build mode: fast (linux/amd64 only)"
else
echo "value=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT
echo "fast=false" >> $GITHUB_OUTPUT
echo "Build mode: full (linux/amd64,linux/arm64)"
fi
shell: bash
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
with:
platforms: 'linux/arm64'
if: steps.platforms.outputs.fast != 'true'
- name: Setup Blacksmith Builder
uses: useblacksmith/setup-docker-builder@v1
- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: avaprotocol/avs-dev
tags: |
# Primary tag (e.g., v1.6.0 or staging-abc1234)
type=raw,value=${{ steps.vars.outputs.PRIMARY_DOCKER_TAG }}
# Always set latest tag for any build
type=raw,value=latest
- name: Build and push avs-dev Docker image
uses: useblacksmith/build-push-action@v2
with:
build-args: |
RELEASE_TAG=${{ steps.vars.outputs.RELEASE_TAG_ARG }}
COMMIT_SHA=${{ steps.vars.outputs.SHORT_SHA }}
platforms: ${{ steps.platforms.outputs.value }}
context: .
file: dockerfiles/operator.Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}