-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (76 loc) · 2.63 KB
/
ecr-deploy.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Docker image build and publish
on:
push:
workflow_dispatch:
inputs:
path_to_dockerfile:
description: Path to the dockerfile (default = 'Dockerfile')
default: "gohelloworld/Dockerfile"
type: string
docker_build_dir:
description: Docker build directory (default = '.')
default: "gohelloworld"
type: string
image_tag:
description: Tag to apply to images.
type: string
default: snapshot-artifact
lifecycle_policy_file:
description: Path to the lifecycle policy JSON file (default = 'policy.json')
default: "e2e-test/policy.json"
type: string
github_iam_role:
description: Name of the IAM Role for adding access to ECR repo
default: "GHActions20240920000443762500000001"
type: string
aws_account_id:
description: AWS Account ID
type: string
aws_region:
description: Target AWS Region
default: "us-east-1"
type: string
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: "us-east-1"
- 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: ${{ inputs.image_tag }}
run: |
docker build "${{ inputs.docker_build_dir }}" -f "${{ inputs.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"