Skip to content

Commit aa40d73

Browse files
committed
CI: Update container build and automate push to prod
1 parent 52ad711 commit aa40d73

4 files changed

Lines changed: 311 additions & 74 deletions

File tree

.github/workflows/deploy_containers.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 97 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,130 @@
1-
name: (dev) Docker image build and publish
1+
name: Build and Deploy Dev Container Images
22
on:
33
workflow_dispatch:
44
inputs:
5-
instrument_name:
6-
description: 'Instrument name'
5+
instruments:
6+
description: 'Instruments to build'
77
required: true
8-
type: string
8+
type: choice
9+
options:
10+
- all
11+
- codice
12+
- glows
13+
- hit
14+
- hi
15+
- ialirt
16+
- idex
17+
- lo
18+
- mag
19+
- spacecraft
20+
- swapi
21+
- swe
22+
- ultra
23+
default: all
924
git_url:
1025
description: 'IMAP Processing Git URL to build from'
11-
required: true
26+
required: false
1227
type: string
1328
default: 'https://github.com/IMAP-Science-Operations-Center/imap_processing.git@dev'
1429

15-
# concurrency required to avoid lock contention during ECR provisioning
16-
concurrency: ci-${{ github.repository }}-${{ inputs.instrument_name }}-dev-docker-pipeline
30+
# Prevent multiple builds running concurrently
31+
concurrency:
32+
group: container-build-dev-${{ github.repository }}
33+
cancel-in-progress: false
34+
35+
env:
36+
# IMAP instruments - keep in sync with imap_data_access.VALID_INSTRUMENTS
37+
VALID_INSTRUMENTS: "codice,glows,hit,hi,ialirt,idex,lo,mag,spacecraft,swapi,swe,ultra"
38+
DEV_ACCOUNT: "449431850278"
39+
AWS_REGION: "us-west-2"
1740

1841
jobs:
19-
deploy_containers:
42+
prepare:
43+
runs-on: ubuntu-latest
44+
outputs:
45+
instruments: ${{ steps.setup.outputs.instruments }}
46+
matrix: ${{ steps.setup.outputs.matrix }}
47+
steps:
48+
- name: Setup build parameters
49+
id: setup
50+
run: |
51+
# Determine which instruments to build
52+
if [ "${{ inputs.instruments }}" = "all" ]; then
53+
instruments="${{ env.VALID_INSTRUMENTS }}"
54+
else
55+
instruments="${{ inputs.instruments }}"
56+
fi
57+
58+
# Clean up whitespace and convert to JSON array
59+
instruments=$(echo "$instruments" | tr ',' '\n' | tr -d ' ' | grep -v '^$' | jq -R . | jq -s .)
60+
61+
echo "instruments=$instruments" >> $GITHUB_OUTPUT
62+
echo "matrix={\"instrument\": $instruments}" >> $GITHUB_OUTPUT
63+
64+
echo "Building instruments: $instruments"
65+
echo "Git URL: ${{ inputs.git_url }}"
66+
67+
build_and_push:
68+
needs: prepare
2069
runs-on: ubuntu-latest
21-
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
70+
strategy:
71+
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
72+
fail-fast: false # Continue building other instruments if one fails
2273
permissions:
2374
id-token: write
2475
contents: read
25-
2676
steps:
27-
- uses: actions/checkout@v3
77+
- name: Checkout repository
78+
uses: actions/checkout@v4
2879

29-
# https://github.com/aws-actions/configure-aws-credentials
3080
- name: Configure AWS credentials
3181
uses: aws-actions/configure-aws-credentials@v4
3282
with:
33-
role-to-assume: arn:aws:iam::449431850278:role/GitHubDeploy
34-
aws-region: us-west-2
83+
role-to-assume: arn:aws:iam::${{ env.DEV_ACCOUNT }}:role/GitHubDeploy
84+
aws-region: ${{ env.AWS_REGION }}
85+
role-session-name: GitHubActions-${{ matrix.instrument }}-dev
3586

3687
- name: Login to Amazon ECR
3788
id: login-ecr
3889
uses: aws-actions/amazon-ecr-login@v2
3990
with:
40-
mask-password: "true" # see: https://github.com/aws-actions/amazon-ecr-login#docker-credentials
91+
mask-password: "true"
4192

4293
- name: Build, tag, and push docker image to Amazon ECR
4394
env:
4495
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
45-
REPOSITORY: ${{ inputs.instrument_name}}
96+
REPOSITORY: ${{ matrix.instrument }}-repo
4697
IMAGE_TAG: latest
4798
run: |
48-
docker build -t $REGISTRY/$REPOSITORY-repo:$IMAGE_TAG \
99+
echo "Building image: $REGISTRY/$REPOSITORY:$IMAGE_TAG"
100+
101+
# Build with dev dockerfile and git URL
102+
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG \
49103
--build-arg GIT_URL=${{ inputs.git_url }} \
50104
-f dockerfiles/Dockerfile.dev .
51-
docker push $REGISTRY/$REPOSITORY-repo:$IMAGE_TAG
105+
106+
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
107+
echo "✅ Successfully pushed $REGISTRY/$REPOSITORY:$IMAGE_TAG"
108+
109+
summary:
110+
needs: [prepare, build_and_push]
111+
runs-on: ubuntu-latest
112+
if: always()
113+
steps:
114+
- name: Build Summary
115+
run: |
116+
echo "## Dev Container Build Summary" >> $GITHUB_STEP_SUMMARY
117+
echo "" >> $GITHUB_STEP_SUMMARY
118+
echo "**Environment:** dev" >> $GITHUB_STEP_SUMMARY
119+
echo "**Account:** ${{ env.DEV_ACCOUNT }}" >> $GITHUB_STEP_SUMMARY
120+
echo "**Instruments:** ${{ join(fromJson(needs.prepare.outputs.instruments), ', ') }}" >> $GITHUB_STEP_SUMMARY
121+
echo "**Git URL:** ${{ inputs.git_url }}" >> $GITHUB_STEP_SUMMARY
122+
echo "" >> $GITHUB_STEP_SUMMARY
123+
124+
if [ "${{ needs.build_and_push.result }}" = "success" ]; then
125+
echo "✅ All builds completed successfully" >> $GITHUB_STEP_SUMMARY
126+
elif [ "${{ needs.build_and_push.result }}" = "failure" ]; then
127+
echo "❌ Some builds failed" >> $GITHUB_STEP_SUMMARY
128+
else
129+
echo "⚠️ Build status: ${{ needs.build_and_push.result }}" >> $GITHUB_STEP_SUMMARY
130+
fi

0 commit comments

Comments
 (0)