Skip to content

Commit 1dfd909

Browse files
committed
push image to github container registry instead of public ecr
1 parent e8d75f8 commit 1dfd909

File tree

1 file changed

+66
-31
lines changed

1 file changed

+66
-31
lines changed

.github/workflows/deploy-to-ecr.yaml

+66-31
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,58 @@
1-
# name: Deploy to AWS ECR
1+
# # name: Deploy to AWS ECR
2+
3+
# # on:
4+
# # push:
5+
# # branches:
6+
# # - main
7+
8+
# # env:
9+
# # AWS_REGION: "eu-central-1" # set this to your preferred AWS region, e.g. us-west-1
10+
11+
# # jobs:
12+
# # deploy:
13+
# # runs-on: ubuntu-latest
14+
15+
# # permissions:
16+
# # contents: read
17+
# # id-token: write
18+
19+
# # steps:
20+
# # # Checkout the code
21+
# # - name: Checkout Code
22+
# # uses: actions/checkout@v3
23+
24+
# # # Set up AWS credentials
25+
# # - name: Configure AWS credentials
26+
# # uses: aws-actions/configure-aws-credentials@v4
27+
# # with:
28+
# # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
29+
# # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
30+
# # aws-region: ${{ env.AWS_REGION }}
31+
32+
# # # Login to Amazon ECR
33+
# # - name: Login to Amazon ECR
34+
# # id: login-ecr
35+
# # uses: aws-actions/amazon-ecr-login@v2
36+
37+
# # # Build and tag the Docker image
38+
# # - name: Build and Tag Docker Image
39+
# # run: |
40+
# # docker build -t kotlin-spring-postgres-demo-app .
41+
# # docker tag kotlin-spring-postgres-demo-app:latest ${{ steps.login-ecr.outputs.registry }}/kotlin-spring-postgres-demo-app:latest
42+
43+
# # # Push the Docker image to Amazon ECR
44+
# # - name: Push Docker Image to Amazon ECR
45+
# # run: |
46+
# # docker push ${{ steps.login-ecr.outputs.registry }}/kotlin-spring-postgres-demo-app:latest
47+
# name: Deploy to Public AWS ECR
248

349
# on:
450
# push:
551
# branches:
652
# - main
753

854
# env:
9-
# AWS_REGION: "eu-central-1" # set this to your preferred AWS region, e.g. us-west-1
55+
# AWS_REGION: "us-east-1" # Your preferred AWS region
1056

1157
# jobs:
1258
# deploy:
@@ -28,65 +74,54 @@
2874
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
2975
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
3076
# aws-region: ${{ env.AWS_REGION }}
31-
32-
# # Login to Amazon ECR
33-
# - name: Login to Amazon ECR
34-
# id: login-ecr
35-
# uses: aws-actions/amazon-ecr-login@v2
77+
78+
# # Authenticate to Amazon Public ECR
79+
# - name: Login to Public ECR
80+
# run: |
81+
# aws ecr-public get-login-password --region ${{ env.AWS_REGION }} | docker login --username AWS --password-stdin public.ecr.aws
3682

3783
# # Build and tag the Docker image
3884
# - name: Build and Tag Docker Image
3985
# run: |
4086
# docker build -t kotlin-spring-postgres-demo-app .
41-
# docker tag kotlin-spring-postgres-demo-app:latest ${{ steps.login-ecr.outputs.registry }}/kotlin-spring-postgres-demo-app:latest
87+
# docker tag kotlin-spring-postgres-demo-app:latest public.ecr.aws/b1y7k5v4/kotlin-spring-postgres-demo-app:latest
4288

43-
# # Push the Docker image to Amazon ECR
44-
# - name: Push Docker Image to Amazon ECR
89+
# # Push the Docker image to Amazon Public ECR
90+
# - name: Push Docker Image to Public ECR
4591
# run: |
46-
# docker push ${{ steps.login-ecr.outputs.registry }}/kotlin-spring-postgres-demo-app:latest
47-
name: Deploy to Public AWS ECR
92+
# docker push public.ecr.aws/b1y7k5v4/kotlin-spring-postgres-demo-app:latest
93+
name: Deploy to GitHub Container Registry
4894

4995
on:
5096
push:
5197
branches:
5298
- main
5399

54-
env:
55-
AWS_REGION: "us-east-1" # Your preferred AWS region
56-
57100
jobs:
58101
deploy:
59102
runs-on: ubuntu-latest
60103

61104
permissions:
62105
contents: read
63-
id-token: write
106+
packages: write # Required to push to GitHub Container Registry
64107

65108
steps:
66109
# Checkout the code
67110
- name: Checkout Code
68111
uses: actions/checkout@v3
69112

70-
# Set up AWS credentials
71-
- name: Configure AWS credentials
72-
uses: aws-actions/configure-aws-credentials@v4
73-
with:
74-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
75-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
76-
aws-region: ${{ env.AWS_REGION }}
77-
78-
# Authenticate to Amazon Public ECR
79-
- name: Login to Public ECR
113+
# Authenticate to GitHub Container Registry
114+
- name: Log in to GitHub Container Registry
80115
run: |
81-
aws ecr-public get-login-password --region ${{ env.AWS_REGION }} | docker login --username AWS --password-stdin public.ecr.aws
116+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
82117
83118
# Build and tag the Docker image
84119
- name: Build and Tag Docker Image
85120
run: |
86121
docker build -t kotlin-spring-postgres-demo-app .
87-
docker tag kotlin-spring-postgres-demo-app:latest public.ecr.aws/b1y7k5v4/kotlin-spring-postgres-demo-app:latest
122+
docker tag kotlin-spring-postgres-demo-app:latest ghcr.io/${{ github.repository_owner }}/kotlin-spring-postgres-demo-app:latest
88123
89-
# Push the Docker image to Amazon Public ECR
90-
- name: Push Docker Image to Public ECR
124+
# Push the Docker image to GHCR
125+
- name: Push Docker Image to GitHub Container Registry
91126
run: |
92-
docker push public.ecr.aws/b1y7k5v4/kotlin-spring-postgres-demo-app:latest
127+
docker push ghcr.io/${{ github.repository_owner }}/kotlin-spring-postgres-demo-app:latest

0 commit comments

Comments
 (0)