Skip to content

Commit f8eb1df

Browse files
committed
Create docker build GHA
1 parent 75691e1 commit f8eb1df

2 files changed

Lines changed: 105 additions & 38 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Docker Build
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag_latest:
7+
description: 'Tag as latest'
8+
required: true
9+
type: choice
10+
options:
11+
- 'true'
12+
- 'false'
13+
default: 'true'
14+
push:
15+
# temp disable branch filter for testing
16+
#branches: [main]
17+
paths:
18+
- 'docker/**'
19+
- 'scripts/setup_*.sh'
20+
- 'src/holosoma_inference/docker/Dockerfile'
21+
- 'src/holosoma_retargeting/docker/Dockerfile'
22+
23+
permissions:
24+
contents: read
25+
26+
env:
27+
ECR_REPO: 982423663241.dkr.ecr.us-west-2.amazonaws.com
28+
29+
jobs:
30+
build:
31+
strategy:
32+
fail-fast: false # continue on one build failing
33+
matrix:
34+
environment:
35+
# just inference for first version, quickest to build and debug issues in GHA
36+
- inference
37+
# - holosoma
38+
# - retargeting
39+
# - isaacsim
40+
# - isaacgym
41+
# - mujoco
42+
#TODO: add mujoco warp
43+
name: Build ${{ matrix.environment }} Docker Image
44+
continue-on-error: true
45+
runs-on: codebuild-holosoma-cpu-build-${{ github.run_id }}-${{ github.run_attempt }}
46+
env:
47+
# image name should be `holosoma` or `holsoma-${environment}`
48+
IMAGE_NAME: ${{ matrix.environment == 'holosoma' && '' || 'holosoma-' }}${{ matrix.environment }}
49+
steps:
50+
- name: Checkout code
51+
uses: actions/checkout@v6
52+
53+
- name: Generate image tag
54+
id: tag
55+
run: echo "tag=$(date -u +%Y_%m%d_%H%M)" >> "$GITHUB_OUTPUT"
56+
57+
- name: Build Docker image
58+
env:
59+
IMAGE_TAG: ${{ steps.tag.outputs.tag }}
60+
run: |
61+
./docker/build_and_push.sh "${{ matrix.environment }}" \
62+
"${{ inputs.tag_latest == 'true' && '--latest' || '' }}"
63+
64+
- name: Summary
65+
run: |
66+
echo "## Docker Build Summary" >> "$GITHUB_STEP_SUMMARY"
67+
echo "- **Tag:** \`${{ steps.tag.outputs.tag }}\`" >> "$GITHUB_STEP_SUMMARY"
68+
echo "- **Image:** \`${{ env.ECR_REPO }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }}\`" >> "$GITHUB_STEP_SUMMARY"

docker/build_and_push.sh

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Usage:
66
# bash docker/build_and_push.sh # build & push all images
77
# bash docker/build_and_push.sh mujoco retarget # only matching images
8-
# bash docker/build_and_push.sh --no-push # build only, skip push
8+
# bash docker/build_and_push.sh --latest # also tag and push as :latest
99
# bash docker/build_and_push.sh --dry-run # print commands, do nothing
1010
#
1111
# Environment variables:
@@ -34,13 +34,13 @@ IMAGES=(
3434
)
3535

3636
# ── Parse flags ──────────────────────────────────────────────────────
37-
NO_PUSH=false
37+
TAG_LATEST=false
3838
DRY_RUN=false
3939
FILTERS=()
4040

4141
for arg in "$@"; do
4242
case "$arg" in
43-
--no-push) NO_PUSH=true ;;
43+
--latest) TAG_LATEST=true ;;
4444
--dry-run) DRY_RUN=true ;;
4545
--help|-h)
4646
sed -n '2,/^$/{ s/^# \?//; p }' "$0"
@@ -81,32 +81,30 @@ for cmd in docker; do
8181
fi
8282
done
8383

84-
if ! $NO_PUSH && ! $DRY_RUN; then
84+
if ! $DRY_RUN; then
8585
if ! command -v aws &>/dev/null; then
8686
echo "Error: aws CLI is not installed (required for push)" >&2; exit 1
8787
fi
8888
fi
8989

9090
# ── ECR authentication ──────────────────────────────────────────────
91-
if ! $NO_PUSH; then
92-
echo "==> Configuring ECR credential helper for ${ECR_REPO}"
93-
if ! $DRY_RUN; then
94-
# Ensure docker config dir exists
95-
mkdir -p ~/.docker
96-
97-
# Add ecr-login credential helper for our registry if not already present
98-
if [ ! -f ~/.docker/config.json ]; then
99-
echo '{}' > ~/.docker/config.json
100-
fi
91+
echo "==> Configuring ECR credential helper for ${ECR_REPO}"
92+
if ! $DRY_RUN; then
93+
# Ensure docker config dir exists
94+
mkdir -p ~/.docker
95+
96+
# Add ecr-login credential helper for our registry if not already present
97+
if [ ! -f ~/.docker/config.json ]; then
98+
echo '{}' > ~/.docker/config.json
99+
fi
101100

102-
if ! jq -e ".credHelpers[\"${ECR_REPO}\"]" ~/.docker/config.json &>/dev/null; then
103-
tmp=$(mktemp)
104-
jq --arg repo "$ECR_REPO" '.credHelpers[$repo] = "ecr-login"' ~/.docker/config.json > "$tmp" \
105-
&& mv "$tmp" ~/.docker/config.json
106-
echo " Added ecr-login credential helper for ${ECR_REPO}"
107-
else
108-
echo " ECR credential helper already configured"
109-
fi
101+
if ! jq -e ".credHelpers[\"${ECR_REPO}\"]" ~/.docker/config.json &>/dev/null; then
102+
tmp=$(mktemp)
103+
jq --arg repo "$ECR_REPO" '.credHelpers[$repo] = "ecr-login"' ~/.docker/config.json > "$tmp" \
104+
&& mv "$tmp" ~/.docker/config.json
105+
echo " Added ecr-login credential helper for ${ECR_REPO}"
106+
else
107+
echo " ECR credential helper already configured"
110108
fi
111109
fi
112110

@@ -125,30 +123,31 @@ for entry in "${IMAGES[@]}"; do
125123
echo ""
126124
echo "==> Building ${image_name} from ${dockerfile}"
127125

128-
# tags: date tag + latest
129-
tags=(-t "${full_image}:latest" -t "${full_image}:${TAG}")
126+
# tags: always date tag, optionally latest
127+
tags=(-t "${full_image}:${TAG}")
128+
if $TAG_LATEST; then
129+
tags+=(-t "${full_image}:latest")
130+
fi
130131

131132
if run env DOCKER_BUILDKIT=1 docker build "${tags[@]}" -f "${dockerfile}" "${ROOT_REPO}"; then
132133
echo " Built: ${image_name}"
133134

134-
if ! $NO_PUSH; then
135-
echo " Pushing ${image_name}..."
136-
push_ok=true
135+
echo " Pushing ${image_name}..."
136+
push_ok=true
137+
if ! run docker push "${full_image}:${TAG}"; then
138+
push_ok=false
139+
fi
140+
if $TAG_LATEST; then
137141
if ! run docker push "${full_image}:latest"; then
138142
push_ok=false
139143
fi
140-
if ! run docker push "${full_image}:${TAG}"; then
141-
push_ok=false
142-
fi
144+
fi
143145

144-
if $push_ok; then
145-
SUCCEEDED+=("$image_name")
146-
else
147-
echo " FAILED to push: ${image_name}" >&2
148-
FAILED+=("$image_name")
149-
fi
150-
else
146+
if $push_ok; then
151147
SUCCEEDED+=("$image_name")
148+
else
149+
echo " FAILED to push: ${image_name}" >&2
150+
FAILED+=("$image_name")
152151
fi
153152
else
154153
echo " FAILED to build: ${image_name}" >&2
@@ -196,6 +195,6 @@ if [[ ${#SUCCEEDED[@]} -eq 0 ]] && [[ ${#FAILED[@]} -eq 0 ]]; then
196195
exit 1
197196
fi
198197
echo " Tag: ${TAG}"
199-
$NO_PUSH && echo " (push skipped — --no-push)"
198+
$TAG_LATEST && echo " (also tagged as :latest)"
200199
$DRY_RUN && echo " (dry run — nothing was executed)"
201200
echo " Done."

0 commit comments

Comments
 (0)