Skip to content

Commit 2bde51a

Browse files
committed
final version (fingers crossed)
1 parent 5283c3c commit 2bde51a

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

.github/workflows/publish.yml

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,74 @@
1-
name: Publish image and deploy to staging
1+
name: Build image from main and deploy to staging
22

33
on:
44
push:
55
branches:
66
- main
77
workflow_dispatch:
88

9-
env:
10-
ECR_REPOSITORY_URI: ${{ secrets.AWS_ECR_ACCOUNT }}.dkr.ecr.eu-west-1.amazonaws.com/${{ secrets.ECR_REPOSITORY }}
11-
129
jobs:
1310
prepare-variables:
14-
name: Prepare variables
15-
runs-on: ubuntu-22.04
11+
runs-on: ubuntu-24.04
12+
timeout-minutes: 5
1613
permissions:
1714
contents: read
15+
1816
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+
image_tag: ${{ steps.prepare-variables.outputs.IMAGE_TAG }}
18+
ecr_tags: ${{ steps.prepare-variables.outputs.ECR_TAGS }}
19+
2220
steps:
23-
# Required by generate_image_tags
24-
- name: Checkout
25-
uses: actions/checkout@v6
21+
# Required by prepare-variables
22+
- uses: actions/checkout@v6
2623

27-
- name: Generate image tags
28-
id: generate_image_tags
24+
- name: Prepare variables
25+
id: prepare-variables
2926
env:
30-
IMAGE_REPOSITORY: ${{ env.ECR_REPOSITORY_URI }}
31-
BRANCH_IMAGE_TAG: ${{ github.ref_name }}
27+
# github.ref_name is the plain (no prefix) branch or tag name that
28+
# triggered the workflow (e.g. "main", "v1.2.3").
29+
# We are passing it through env to prevent script injection via crafted
30+
# branch names (e.g. a branch named `; rm -rf /` would be interpolated
31+
# directly into the shell script if using ${{ }} inline).
32+
REF_NAME: ${{ github.ref_name }}
3233
run: |
33-
unique_image_tag="${BRANCH_IMAGE_TAG}-$(git rev-parse --short HEAD)"
34+
set -x
3435
35-
image_tags="${IMAGE_REPOSITORY}:${BRANCH_IMAGE_TAG},${IMAGE_REPOSITORY}:${unique_image_tag}"
36+
image_tag_unique="${REF_NAME}-$(git rev-parse --short HEAD)"
37+
ecr_tags="${image_tag_unique},${REF_NAME}-latest"
3638
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
39+
echo "IMAGE_TAG=${image_tag_unique}" >> $GITHUB_OUTPUT
40+
echo "ECR_TAGS=${ecr_tags}" >> $GITHUB_OUTPUT
4041
4142
4243
build-push:
43-
needs: prepare-variables
44-
uses: saleor/saleor-internal-actions/.github/workflows/build-push-image-multi-platform.yaml@92c29aa0e4545de579b892b2ef9f2d6366c29c11 # v1.5.2
44+
needs: [prepare-variables]
45+
uses: saleor/saleor-internal-actions/.github/workflows/build-push-image-multi-platform.yaml@9c7a814c011945f26f0aa1191fc9c62de45477c2 # v1.7.0
46+
4547
permissions:
4648
contents: read
4749
id-token: write # needed for AWS/ECR login
4850
packages: write # needed for GHCR (not used, but required permission)
51+
4952
with:
50-
checkout-ref: ${{ github.ref_name }}
53+
tags: ${{ needs.prepare-variables.outputs.ecr_tags }}
5154

5255
enable-aws-ecr: true
5356
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 }}
5657

57-
amd64-runner-image: ubuntu-24.04
58-
arm64-runner-image: ubuntu-24.04-arm
58+
# NOTE: we use 2 cores instead of 4 because it's cheaper and doesn't impact
59+
# the speed.
60+
arm64-runner-image: ubuntu-24.04-arm64-2cores
5961

6062
secrets:
63+
oci-full-repository: ${{ secrets.AWS_ECR_ACCOUNT }}.dkr.ecr.eu-west-1.amazonaws.com/${{ secrets.ECR_REPOSITORY }}
6164
aws-ecr-role-to-assume: arn:aws:iam::${{ secrets.AWS_STAGING_ACCOUNT_ID }}:role/${{ secrets.AWS_APPS_SALEOR_MCP_STAGING_CICD_ROLE_NAME }}
6265
aws-ecr-registries: ${{ secrets.AWS_ECR_ACCOUNT }}
6366

6467
deploy:
6568
needs: [prepare-variables, build-push]
66-
runs-on: ubuntu-22.04
69+
runs-on: ubuntu-24.04
6770
permissions: {}
71+
6872
steps:
6973
- name: Get Token
7074
id: get-token
@@ -76,15 +80,14 @@ jobs:
7680
- name: Trigger staging deployment
7781
env:
7882
GITHUB_TOKEN: ${{ steps.get-token.outputs.token }}
79-
UNIQUE_IMAGE_TAG: ${{ needs.prepare-variables.outputs.unique_image_tag }}
83+
IMAGE_TAG: ${{ needs.prepare-variables.outputs.image_tag }}
8084
run: |
8185
payload=$(
82-
jq --arg image_tag "$UNIQUE_IMAGE_TAG" -n '{
86+
jq -n --arg image_tag "$IMAGE_TAG" '{
8387
"event_type": "saleor-mcp-staging",
8488
"client_payload": {
8589
"image_tag": $image_tag
8690
}
8791
}'
8892
)
89-
9093
gh api /repos/saleor/saleor-cloud-deployments/dispatches --input - <<< "$payload"

0 commit comments

Comments
 (0)