name: "[Build/Push] docker image" permissions: packages: write contents: read id-token: write on: workflow_call: inputs: image_name: type: string required: true build-args: type: string required: false aws-account-id: type: string required: false default: "538326561891" environment: type: string required: true push: type: boolean required: true outputs: image_registry: description: Docker image repository value: ${{ jobs.build-and-push-image.outputs.registry }} jobs: build-and-push-image: runs-on: ubuntu-latest outputs: registry: ${{ steps.login-ecr.outputs.registry }} image_tag: ${{ inputs.image_name_tag }} image: ${{ steps.login-ecr.outputs.registry }}/${{ inputs.image_name }} steps: - name: Checkout code uses: actions/checkout@v6 - name: Set up QEMU uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 with: platforms: arm64 - name: Set up Docker Buildx uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v6 with: role-to-assume: arn:aws:iam::${{ inputs.aws-account-id }}:role/github_actions_ecr role-session-name: GithubActionsCloudInfrastructure aws-region: eu-central-1 - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v2 - name: Setup docker tags and labels id: meta uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 with: images: | ${{ steps.login-ecr.outputs.registry }}/${{ inputs.image_name }} tags: | type=ref,event=tag,enable=${{ inputs.environment == 'prod' }} type=raw,value=latest,enable=${{ inputs.environment == 'prod' }} type=ref,event=branch,enable=${{ inputs.environment == 'dev' }} type=ref,event=pr,enable=${{ inputs.environment == 'dev' }} type=sha,format=long,enable=${{ inputs.environment == 'dev' }} - name: Build and push image uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile platforms: linux/amd64,linux/arm64 push: ${{ inputs.push }} provenance: false tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max build-args: | BUILDKIT_INLINE_CACHE=1