Skip to content

use environment variables #6

use environment variables

use environment variables #6

Workflow file for this run

name: Docker image build and publish
on:
push:
jobs:
docker:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
outputs:
image_tag: ${{ steps.build-publish.outputs.image_tag }}
full_image: ${{ steps.build-publish.outputs.full_image }}
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22.x'
- name: install dependencies
run: go get .
working-directory: ./gohelloworld
- name: Test
run: go test .
working-directory: ./gohelloworld
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: arn:aws:iam::509399598081:role/GHActions20240920000443762500000001
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registries: ${{ env.AWS_ACCOUNT_ID }}
- name: Build, tag, and push image to Amazon ECR
id: build-publish
shell: bash
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.ECR_REPO_NAME }}
IMAGE_TAG: ${{ env.IMAGE_TAG }}
run: |
docker build "${{ env.DOCKER_BUILD_DIR }}" -f "${{ env.PATH_TO_DOCKERFILE }}" -t "$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
docker push "$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
echo "IMAGE $IMAGE_TAG is pushed to $ECR_REGISTRY/$ECR_REPOSITORY"
echo "image_tag=$IMAGE_TAG"
echo "full_image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"