Skip to content

Commit

Permalink
feat: upload image to ecr
Browse files Browse the repository at this point in the history
  • Loading branch information
yourzinc committed Jan 16, 2024
1 parent 36439d7 commit cd1c772
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,39 @@ on:
push

env:
BUCKET_NAME : "aws-github-actions-011624"
AWS_REGION : "ap-northeast-2"
ROLE_NAME : "arn:aws:iam::582765306680:role/github-actions-role"
REPOSITORY_NAME : "aws-github-actions-011624"

permissions:
id-token: write
contents: read

jobs:
S3PackageUpload:
ECRImageUpload:
runs-on: ubuntu-latest
steps:

- name: Git clone the repository
- name: Checkout repo
uses: actions/checkout@v4

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.ROLE_NAME }}
role-session-name: samplerolesession
aws-region: ${{ env.AWS_REGION }}

- name: Copy README.md to s3
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ env.REPOSITORY_NAME }}
IMAGE_TAG: ${{ github.sha }}
run: |
aws s3 cp ./README.md s3://${{ env.BUCKET_NAME }}/
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
echo "Pushing image to ECR..."
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM nginx
COPY ./index.html /usr/share/nginx/html
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Welcome to My Website</title>
</head>
<body>
<h1>Hello from Nginx!</h1>
<p>This is a simple static HTML page served by Nginx in a Docker container.</p>
</body>
</html>

0 comments on commit cd1c772

Please sign in to comment.