|
| 1 | +name: Build and Test Credential Helper Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + |
| 7 | +env: |
| 8 | + STAGING_REGISTRY: 264252446756.dkr.ecr.us-east-1.amazonaws.com |
| 9 | + STAGING_REPOSITORY: credential-helper-staging |
| 10 | + AWS_REGION: us-east-1 |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + packages: write |
| 15 | + id-token: write # This is required for requesting the JWT for AWS authentication |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-and-push: |
| 19 | + name: Build Docker Images and Push to Staging Repository |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + include: |
| 23 | + - os: ubuntu-24.04 |
| 24 | + platform: amd64 |
| 25 | + - os: ubuntu-24.04-arm |
| 26 | + platform: arm64 |
| 27 | + runs-on: ${{ matrix.os }} |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Configure AWS credentials |
| 34 | + uses: aws-actions/configure-aws-credentials@master |
| 35 | + with: |
| 36 | + role-to-assume: arn:aws:iam::264252446756:role/GithubActionsAccessRole |
| 37 | + aws-region: ${{ env.AWS_REGION }} |
| 38 | + |
| 39 | + - name: Login to Amazon ECR |
| 40 | + id: login-ecr |
| 41 | + uses: aws-actions/amazon-ecr-login@v2 |
| 42 | + |
| 43 | + - name: Extract Version from Makefile |
| 44 | + id: extract-version |
| 45 | + run: | |
| 46 | + VERSION=$(grep '^VERSION=' Makefile | cut -d'=' -f2) |
| 47 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 48 | + echo "Extracted version: $VERSION" |
| 49 | +
|
| 50 | + - name: Build and Push Docker image |
| 51 | + uses: docker/build-push-action@v5 |
| 52 | + with: |
| 53 | + context: . |
| 54 | + file: ./docker_image_resources/Dockerfile |
| 55 | + platforms: linux/${{ matrix.platform }} |
| 56 | + push: true |
| 57 | + build-args: | |
| 58 | + VERSION=${{ steps.extract-version.outputs.version }} |
| 59 | + tags: | |
| 60 | + ${{ env.STAGING_REGISTRY }}/${{ env.STAGING_REPOSITORY }}:${{ github.sha }}-${{ matrix.platform }} |
| 61 | + provenance: false # provenance must be disabled in order to prevent manifest creation failures |
| 62 | + |
| 63 | + test-and-scan: |
| 64 | + name: Test and Scan Docker Images |
| 65 | + needs: build-and-push |
| 66 | + strategy: |
| 67 | + matrix: |
| 68 | + include: |
| 69 | + - os: ubuntu-24.04 |
| 70 | + platform: amd64 |
| 71 | + - os: ubuntu-24.04-arm |
| 72 | + platform: arm64 |
| 73 | + runs-on: ${{ matrix.os }} |
| 74 | + |
| 75 | + steps: |
| 76 | + - name: Checkout Repository |
| 77 | + uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - name: Configure AWS Credentials |
| 80 | + uses: aws-actions/configure-aws-credentials@master |
| 81 | + with: |
| 82 | + role-to-assume: arn:aws:iam::264252446756:role/GithubActionsAccessRole |
| 83 | + aws-region: ${{ env.AWS_REGION }} |
| 84 | + |
| 85 | + - name: Login to Amazon ECR |
| 86 | + id: login-ecr |
| 87 | + uses: aws-actions/amazon-ecr-login@v2 |
| 88 | + |
| 89 | + - name: Set up Test Environment |
| 90 | + env: |
| 91 | + PCA_ARN: arn:aws:acm-pca:us-east-1:264252446756:certificate-authority/807cc589-2b5a-4976-a0d8-eeca654e7916 |
| 92 | + run: | |
| 93 | + MAX_PULL_ATTEMPTS=3 |
| 94 | + PULL_ATTEMPT=0 |
| 95 | + until docker pull ${{ env.STAGING_REGISTRY }}/${{ env.STAGING_REPOSITORY }}:${{ github.sha }}-${{matrix.platform}}; do |
| 96 | + PULL_ATTEMPT=$((PULL_ATTEMPT + 1)) |
| 97 | + if [ $PULL_ATTEMPT -ge $MAX_PULL_ATTEMPTS ]; then |
| 98 | + echo "Failed to pull image after $MAX_PULL_ATTEMPTS attempts" |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | + echo "Pull attempt $PULL_ATTEMPT failed, waiting before retry..." |
| 102 | + sleep 10 |
| 103 | + done |
| 104 | + |
| 105 | + echo "REPOSITORY=${{ env.STAGING_REPOSITORY }}" >> $GITHUB_ENV |
| 106 | +
|
| 107 | + mkdir -p docker_image_resources/tests/certs |
| 108 | + |
| 109 | + ./docker_image_resources/tests/scripts/setup-key-and-cert-pca.sh "$PCA_ARN" |
| 110 | + |
| 111 | + - name: Test the ${{matrix.platform}} Docker Image |
| 112 | + env: |
| 113 | + TRUST_ANCHOR_ARN: arn:aws:rolesanywhere:us-east-1:264252446756:trust-anchor/11436419-d765-4a1f-a65e-441a197ed5fc |
| 114 | + PROFILE_ARN: arn:aws:rolesanywhere:us-east-1:264252446756:profile/24a0d47d-9e88-4be8-97fc-a55422105b6c |
| 115 | + ROLE_ARN: arn:aws:iam::264252446756:role/CredentialHelperTestingRole |
| 116 | + VERSION: ${{ github.sha }}-${{matrix.platform}} |
| 117 | + REGISTRY: ${{ env.STAGING_REGISTRY }} # Needed due to test suite using this variable |
| 118 | + run: | |
| 119 | + # Run basic version test |
| 120 | + echo "Testing version command:" |
| 121 | + docker run --rm ${{ env.STAGING_REGISTRY }}/${{ env.STAGING_REPOSITORY }}:${{ github.sha }}-${{matrix.platform}} version |
| 122 | +
|
| 123 | + # Run Integration Tests |
| 124 | + cd docker_image_resources |
| 125 | + ./tests/run-tests.sh |
| 126 | + |
| 127 | + - name: Install Trivy Image Scanner |
| 128 | + uses: aquasecurity/setup-trivy@v0.2.0 |
| 129 | + with: |
| 130 | + cache: true |
| 131 | + version: v0.63.0 |
| 132 | + |
| 133 | + - name: Scan Docker image with Trivy |
| 134 | + run: | |
| 135 | + IMAGE_REFERENCE="${{ env.STAGING_REGISTRY }}/${{ env.STAGING_REPOSITORY }}:${{ github.sha }}-${{matrix.platform}}" |
| 136 | + ./docker_image_resources/tests/scripts/scan-image.sh "$IMAGE_REFERENCE" |
0 commit comments