From 93ac9c7624ecdada4ab1d00886647d59bfe06b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=ED=95=98=EC=84=B1?= Date: Tue, 26 Sep 2023 23:25:13 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=82=EF=B8=8F::=20(#main)=20cd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CD.yml | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml index 4489bed71..10a9cdfb4 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/CD.yml @@ -23,17 +23,21 @@ jobs: - name: Build with Gradle run: ./gradlew --build-cache build - - name: Login to Dockerhub - uses: docker/login-action@v1 + - name: Login to ECR + id: ecr + uses: elgohr/ecr-login-action@master with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + access_key: ${{ secrets.AWS_ACCESS }} + secret_access_key: ${{ secrets.AWS_SECRET }} + region: ${{ secrets.AWS_REGION }} - - name: Docker Build - run: docker build -t ${{ secrets.DOCKER_IMAGE }} . - - - name: Push on Dockerhub - run: docker push ${{ secrets.DOCKER_IMAGE }} + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@v5 + with: + name: ${{ secrets.ECR_REPOSITORY }} + username: ${{ steps.ecr.outputs.username }} + password: ${{ steps.ecr.outputs.password }} + registry: ${{ steps.ecr.outputs.registry }} - name: Connect EC2 & Deploy Docker Image uses: appleboy/ssh-action@master @@ -44,10 +48,11 @@ jobs: key: ${{ secrets.EC2_KEY }} script: | cd jobis - docker pull ${{ secrets.DOCKER_IMAGE }} + aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.ECR_REPOSITORY }} + docker pull ${{ secrets.ECR_REPOSITORY }} docker rm -f jobis-server docker image prune -a -f - docker run --name jobis-server -dp 8080:8080 --env-file .env ${{ secrets.DOCKER_IMAGE }} + docker run --name jobis-server -dp 8080:8080 --env-file .env ${{ secrets.ECR_REPOSITORY }}