|
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + ECR_REPOSITORY_URI: ${{ secrets.AWS_ECR_ACCOUNT }}.dkr.ecr.eu-west-1.amazonaws.com/${{ secrets.ECR_REPOSITORY }} |
7 | 11 |
|
8 | 12 | jobs: |
9 | | - publish: |
10 | | - runs-on: ubuntu-24.04 |
| 13 | + prepare-variables: |
| 14 | + name: Prepare variables |
| 15 | + runs-on: ubuntu-22.04 |
11 | 16 | permissions: |
12 | | - id-token: write # needed by aws-actions/configure-aws-credentials |
13 | 17 | contents: read |
14 | | - env: |
15 | | - AWS_REGION: eu-west-1 |
16 | | - |
| 18 | + outputs: |
| 19 | + image_tags: ${{ steps.generate_image_tags.outputs.image_tags }} |
| 20 | + unique_image_tag: ${{ steps.generate_image_tags.outputs.unique_image_tag }} |
| 21 | + ecr_repo_uri: ${{ steps.generate_image_tags.outputs.ecr_repo_uri }} |
17 | 22 | steps: |
18 | | - - name: Checkout repository |
19 | | - uses: actions/checkout@v5 |
20 | | - |
21 | | - - name: Set up QEMU |
22 | | - uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 |
23 | | - with: |
24 | | - platforms: arm64 |
| 23 | + # Required by generate_image_tags |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v6 |
25 | 26 |
|
26 | | - - name: Set up Docker Buildx |
27 | | - uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 |
28 | | - with: |
29 | | - install: true |
30 | | - |
31 | | - - name: Configure AWS credentials |
32 | | - uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 # v5.0.0 |
33 | | - with: |
34 | | - role-to-assume: arn:aws:iam::${{ secrets.AWS_STAGING_ACCOUNT_ID }}:role/${{ secrets.AWS_APPS_SALEOR_MCP_STAGING_CICD_ROLE_NAME }} |
35 | | - aws-region: ${{ env.AWS_REGION }} |
36 | | - |
37 | | - - id: ecr-login |
38 | | - name: Login to Amazon ECR |
39 | | - uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1 |
40 | | - with: |
41 | | - registries: ${{ secrets.AWS_ECR_ACCOUNT }} |
42 | | - |
43 | | - - name: Evaluate image tags |
| 27 | + - name: Generate image tags |
| 28 | + id: generate_image_tags |
44 | 29 | env: |
45 | | - IMAGE_REPOSITORY: ${{ steps.ecr-login.outputs.registry }}/${{ secrets.ECR_REPOSITORY }} |
| 30 | + IMAGE_REPOSITORY: ${{ env.ECR_REPOSITORY_URI }} |
46 | 31 | BRANCH_IMAGE_TAG: ${{ github.ref_name }} |
47 | 32 | run: | |
48 | | - UNIQUE_IMAGE_TAG=${BRANCH_IMAGE_TAG}-$(git rev-parse --short HEAD) |
| 33 | + unique_image_tag="${BRANCH_IMAGE_TAG}-$(git rev-parse --short HEAD)" |
49 | 34 |
|
50 | | - IMAGE_TAGS=${IMAGE_REPOSITORY}:${BRANCH_IMAGE_TAG},${IMAGE_REPOSITORY}:${UNIQUE_IMAGE_TAG} |
| 35 | + image_tags="${IMAGE_REPOSITORY}:${BRANCH_IMAGE_TAG},${IMAGE_REPOSITORY}:${unique_image_tag}" |
51 | 36 |
|
52 | | - echo "UNIQUE_IMAGE_TAG=${UNIQUE_IMAGE_TAG}" >> $GITHUB_ENV |
53 | | - echo "IMAGE_TAGS=${IMAGE_TAGS}" >> $GITHUB_ENV |
| 37 | + echo "unique_image_tag=${unique_image_tag}" >> $GITHUB_OUTPUT |
| 38 | + echo "image_tags=${image_tags}" >> $GITHUB_OUTPUT |
| 39 | + echo "ecr_repo_uri=${IMAGE_REPOSITORY}" >> $GITHUB_OUTPUT |
54 | 40 |
|
55 | | - - name: Build and push |
56 | | - timeout-minutes: 20 |
57 | | - uses: docker/build-push-action@v4 |
| 41 | +
|
| 42 | + build-push: |
| 43 | + needs: prepare-variables |
| 44 | + uses: saleor/saleor-internal-actions/.github/workflows/build-push-image-multi-platform.yaml@92c29aa0e4545de579b892b2ef9f2d6366c29c11 # v1.5.2 |
| 45 | + permissions: |
| 46 | + contents: read |
| 47 | + id-token: write # needed for AWS/ECR login |
| 48 | + packages: write # needed for GHCR (not used, but required permission) |
| 49 | + with: |
| 50 | + checkout-ref: ${{ github.ref_name }} |
| 51 | + |
| 52 | + enable-aws-ecr: true |
| 53 | + aws-ecr-region: eu-west-1 |
| 54 | + oci-full-repository: ${{ needs.prepare-variables.outputs.ecr_repo_uri }} |
| 55 | + tags: ${{ needs.prepare-variables.outputs.image_tags }} |
| 56 | + |
| 57 | + amd64-runner-image: ubuntu-24.04 |
| 58 | + arm64-runner-image: ubuntu-24.04-arm |
| 59 | + |
| 60 | + secrets: |
| 61 | + aws-ecr-role-to-assume: arn:aws:iam::${{ secrets.AWS_STAGING_ACCOUNT_ID }}:role/${{ secrets.AWS_APPS_SALEOR_MCP_STAGING_CICD_ROLE_NAME }} |
| 62 | + aws-ecr-registries: ${{ secrets.AWS_ECR_ACCOUNT }} |
| 63 | + |
| 64 | + deploy: |
| 65 | + needs: [prepare-variables, build-push] |
| 66 | + runs-on: ubuntu-22.04 |
| 67 | + steps: |
| 68 | + - name: Get Token |
| 69 | + id: get-token |
| 70 | + uses: saleor/saleor-internal-actions/request-vault-token@6a0fa7c073b3857a11d414f25a149065fe5a0fcf # v1.4.0 |
58 | 71 | with: |
59 | | - context: . |
60 | | - platforms: linux/amd64,linux/arm64 |
61 | | - push: true |
62 | | - tags: ${{ env.IMAGE_TAGS }} |
63 | | - cache-from: type=gha,scope=buildkit-master |
64 | | - cache-to: type=gha,scope=buildkit-master |
| 72 | + vault-url: ${{ secrets.VAULT_URL }} |
| 73 | + vault-jwt: ${{ secrets.VAULT_JWT }} |
65 | 74 |
|
66 | 75 | - name: Trigger staging deployment |
| 76 | + env: |
| 77 | + GITHUB_TOKEN: ${{ steps.get-token.outputs.token }} |
| 78 | + UNIQUE_IMAGE_TAG: ${{ needs.prepare-variables.outputs.unique_image_tag }} |
67 | 79 | run: | |
68 | | - export GITHUB_TOKEN=$( \ |
69 | | - curl --request GET --url ${{ secrets.VAULT_URL}} --header "Authorization: JWT ${{ secrets.VAULT_JWT }}" | jq -r .token \ |
70 | | - ) |
71 | | -
|
72 | | - echo "::add-mask::$GITHUB_TOKEN" |
73 | | -
|
74 | 80 | payload=$( |
75 | 81 | jq --arg image_tag "$UNIQUE_IMAGE_TAG" -n '{ |
76 | 82 | "event_type": "saleor-mcp-staging", |
|
80 | 86 | }' |
81 | 87 | ) |
82 | 88 |
|
83 | | - gh api /repos/saleor/saleor-cloud-deployments/dispatches --input <(echo "$payload") |
| 89 | + gh api /repos/saleor/saleor-cloud-deployments/dispatches --input - <<< "$payload" |
0 commit comments