-
Notifications
You must be signed in to change notification settings - Fork 28
210 lines (180 loc) · 7.26 KB
/
Copy pathdocker-build.yml
File metadata and controls
210 lines (180 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Auto Build on Docker Image Tag Change
on:
push:
branches: [ main, develop ] # Adjust branches as needed
paths:
- '.env'
workflow_dispatch:
inputs:
compose_profiles:
description: 'Docker Compose profiles to build (comma-separated)'
required: false
default: 'desktop,isaac-sim,ms-airsim'
type: string
env:
DEFAULT_PROFILES: 'desktop,isaac-sim,ms-airsim'
jobs:
check-docker-tag-change:
runs-on: ubuntu-latest
outputs:
tag-changed: ${{ steps.check-changes.outputs.tag-changed }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2 # Fetch current and previous commit
submodules: recursive
- name: Check if VERSION changed
id: check-changes
run: |
# Get the current VERSION value
CURRENT_TAG=$(grep "^VERSION=" .env | cut -d '=' -f2- | tr -d '"' | tr -d "'")
# Get the previous VERSION value
git show HEAD~1:.env > .env.prev 2>/dev/null || echo "" > .env.prev
PREVIOUS_TAG=$(grep "^VERSION=" .env.prev | cut -d '=' -f2- | tr -d '"' | tr -d "'" || echo "")
echo "Current tag: $CURRENT_TAG"
echo "Previous tag: $PREVIOUS_TAG"
if [ "$CURRENT_TAG" != "$PREVIOUS_TAG" ] && [ -n "$CURRENT_TAG" ]; then
echo "VERSION has changed from '$PREVIOUS_TAG' to '$CURRENT_TAG'"
echo "tag-changed=true" >> $GITHUB_OUTPUT
else
echo "VERSION has not changed"
echo "tag-changed=false" >> $GITHUB_OUTPUT
fi
docker-build:
needs: check-docker-tag-change
if: github.event_name == 'workflow_dispatch' || needs.check-docker-tag-change.outputs.tag-changed == 'true'
runs-on: [self-hosted, airstack-ephemeral]
timeout-minutes: 120
permissions:
contents: read
id-token: write # Required for keyless cosign signing via GitHub OIDC
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Log in to Docker Registry
uses: docker/login-action@v3
with:
registry: ${{ vars.DOCKER_REGISTRY_URL }} # e.g., your-registry.com or leave empty for Docker Hub
username: ${{ vars.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
- name: Verify .env file and extract tag
run: |
# Ensure .env file exists and is readable
if [ ! -f .env ]; then
echo "Error: .env file not found"
exit 1
fi
- name: Create dummy omni_pass.env
run: |
# Some compose files expect this file to exist, even if it is empty.
mkdir -p simulation/isaac-sim/docker
: > simulation/isaac-sim/docker/omni_pass.env
# Display the current VERSION for debugging
DOCKER_TAG=$(grep "^VERSION=" .env | cut -d '=' -f2- | tr -d '"' | tr -d "'")
echo "Building with VERSION: $DOCKER_TAG"
if [ -z "$DOCKER_TAG" ]; then
echo "Error: VERSION is empty"
exit 1
fi
- name: Run Docker Compose Build
run: |
# Load environment variables and run docker compose build
set -a # Export all variables
source .env
set +a # Stop exporting
# Always override COMPOSE_PROFILES for all trigger types
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
export COMPOSE_PROFILES="${{ github.event.inputs.compose_profiles || env.DEFAULT_PROFILES }}"
else
export COMPOSE_PROFILES="${{ env.DEFAULT_PROFILES }}"
fi
docker compose build
- name: Run Docker Compose Push
run: |
# Load environment variables and run docker compose push
set -a # Export all variables
source .env
set +a # Stop exporting
# Always override COMPOSE_PROFILES for all trigger types
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
export COMPOSE_PROFILES="${{ github.event.inputs.compose_profiles || env.DEFAULT_PROFILES }}"
else
export COMPOSE_PROFILES="${{ env.DEFAULT_PROFILES }}"
fi
docker compose push
- name: Sign pushed images with Cosign (keyless)
env:
COSIGN_YES: "true"
run: |
set -a
source .env
set +a
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
export COMPOSE_PROFILES="${{ github.event.inputs.compose_profiles || env.DEFAULT_PROFILES }}"
else
export COMPOSE_PROFILES="${{ env.DEFAULT_PROFILES }}"
fi
IMAGES=$(docker compose config --images | sort -u)
if [ -z "$IMAGES" ]; then
echo "No images resolved from compose config; nothing to sign."
exit 1
fi
for IMG in $IMAGES; do
DIGEST=$(docker buildx imagetools inspect "$IMG" --format '{{.Manifest.Digest}}')
if [ -z "$DIGEST" ]; then
echo "Error: could not resolve digest for $IMG"
exit 1
fi
REPO="${IMG%:*}"
REF="${REPO}@${DIGEST}"
echo "Signing $REF"
cosign sign "$REF"
done
- name: Verify Cosign signatures
run: |
set -a
source .env
set +a
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
export COMPOSE_PROFILES="${{ github.event.inputs.compose_profiles || env.DEFAULT_PROFILES }}"
else
export COMPOSE_PROFILES="${{ env.DEFAULT_PROFILES }}"
fi
IMAGES=$(docker compose config --images | sort -u)
for IMG in $IMAGES; do
DIGEST=$(docker buildx imagetools inspect "$IMG" --format '{{.Manifest.Digest}}')
REPO="${IMG%:*}"
REF="${REPO}@${DIGEST}"
echo "Verifying $REF"
cosign verify "$REF" \
--certificate-identity-regexp "^https://github\\.com/${{ github.repository }}/\\.github/workflows/docker-build\\.yml@" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
> /dev/null
done
- name: Optional - Run Docker Compose Up (uncomment if needed)
run: |
# Uncomment the following lines if you also want to start the services
# set -a
# source .env
# set +a
# docker compose up -d
notify:
needs: [check-docker-tag-change, docker-build]
if: always() && (github.event_name == 'workflow_dispatch' || needs.check-docker-tag-change.outputs.tag-changed == 'true')
runs-on: ubuntu-latest
steps:
- name: Notify build and push result
run: |
if [ "${{ needs.docker-build.result }}" == "success" ]; then
echo "✅ Docker Compose build and push completed successfully"
else
echo "❌ Docker Compose build or push failed"
exit 1
fi