|
1 | | -name: (dev) Docker image build and publish |
| 1 | +name: Build and Deploy Dev Container Images |
2 | 2 | on: |
3 | 3 | workflow_dispatch: |
4 | 4 | inputs: |
5 | | - instrument_name: |
6 | | - description: 'Instrument name' |
| 5 | + instruments: |
| 6 | + description: 'Instruments to build' |
7 | 7 | 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 |
9 | 24 | git_url: |
10 | 25 | description: 'IMAP Processing Git URL to build from' |
11 | | - required: true |
| 26 | + required: false |
12 | 27 | type: string |
13 | 28 | default: 'https://github.com/IMAP-Science-Operations-Center/imap_processing.git@dev' |
14 | 29 |
|
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" |
17 | 40 |
|
18 | 41 | 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 |
20 | 69 | 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 |
22 | 73 | permissions: |
23 | 74 | id-token: write |
24 | 75 | contents: read |
25 | | - |
26 | 76 | steps: |
27 | | - - uses: actions/checkout@v3 |
| 77 | + - name: Checkout repository |
| 78 | + uses: actions/checkout@v4 |
28 | 79 |
|
29 | | - # https://github.com/aws-actions/configure-aws-credentials |
30 | 80 | - name: Configure AWS credentials |
31 | 81 | uses: aws-actions/configure-aws-credentials@v4 |
32 | 82 | 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 |
35 | 86 |
|
36 | 87 | - name: Login to Amazon ECR |
37 | 88 | id: login-ecr |
38 | 89 | uses: aws-actions/amazon-ecr-login@v2 |
39 | 90 | with: |
40 | | - mask-password: "true" # see: https://github.com/aws-actions/amazon-ecr-login#docker-credentials |
| 91 | + mask-password: "true" |
41 | 92 |
|
42 | 93 | - name: Build, tag, and push docker image to Amazon ECR |
43 | 94 | env: |
44 | 95 | REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
45 | | - REPOSITORY: ${{ inputs.instrument_name}} |
| 96 | + REPOSITORY: ${{ matrix.instrument }}-repo |
46 | 97 | IMAGE_TAG: latest |
47 | 98 | 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 \ |
49 | 103 | --build-arg GIT_URL=${{ inputs.git_url }} \ |
50 | 104 | -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