From cd1c772f859f1b67b992e65c59af0ad9af48d534 Mon Sep 17 00:00:00 2001 From: yourzinc Date: Tue, 16 Jan 2024 11:57:32 +0900 Subject: [PATCH] feat: upload image to ecr --- .github/workflows/main.yml | 26 ++++++++++++++++++-------- Dockerfile | 2 ++ index.html | 10 ++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 Dockerfile create mode 100644 index.html diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 902db9c..0d855a3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 }}/ \ No newline at end of file + 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" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..539eea1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx +COPY ./index.html /usr/share/nginx/html \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..6072d43 --- /dev/null +++ b/index.html @@ -0,0 +1,10 @@ + + + + Welcome to My Website + + +

Hello from Nginx!

+

This is a simple static HTML page served by Nginx in a Docker container.

+ + \ No newline at end of file