From cfc5d6ea3405b5589254889f7d367aedbbc45d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B7=B9=EB=9D=BD=EC=BD=94=EB=94=A9?= <50691225+DongGeon0908@users.noreply.github.com> Date: Thu, 1 Aug 2024 01:10:06 +0900 Subject: [PATCH] Update docker-gradle-poc.yml --- .github/workflows/docker-gradle-poc.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-gradle-poc.yml b/.github/workflows/docker-gradle-poc.yml index b30b6bb..9f953b2 100644 --- a/.github/workflows/docker-gradle-poc.yml +++ b/.github/workflows/docker-gradle-poc.yml @@ -83,9 +83,8 @@ jobs: run: ./gradlew clean --stacktrace --info build shell: bash - # Docker 이미지 빌드 - - name: docker image build - run: docker build -t ${{ secrets.DOCKER_USERNAME }}/hero-alignlab-api + - name: Make image tag + run: echo "IMAGE_TAG=$ACTIVE_PROFILE-${GITHUB_SHA::7}" >> $GITHUB_ENV # activeProfile-커밋 hash 값 # DockerHub 로그인 - name: docker login @@ -94,9 +93,13 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} + # Docker 이미지 빌드 + - name: docker image build + run: docker build -t ${{ secrets.DOCKER_USERNAME }}/hero-alignlab-api:${{env.IMAGE_TAG}} . + # Docker Hub 이미지 푸시 - name: docker Hub push - run: docker push ${{ secrets.DOCKER_USERNAME }}/hero-alignlab-api + run: docker push ${{ secrets.DOCKER_USERNAME }}/hero-alignlab-api:${{env.IMAGE_TAG}} # Deploy Service - name: Deploy and Start Spring Boot Application @@ -106,10 +109,11 @@ jobs: username: ubuntu key: ${{ secrets.PRIVATE_KEY }} script: | + sudo echo "IMAGE_TAG=${{ env.IMAGE_TAG }}" >> .env echo "${{ secrets.DOCKER_PASSWORD }}" | sudo docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin sudo docker ps - sudo docker pull ${{ secrets.DOCKER_USERNAME }}/hero-alignlab-api + sudo docker pull ${{ secrets.DOCKER_USERNAME }}/hero-alignlab-api:${{env.IMAGE_TAG}} sudo docker stop server || true sudo docker rm server || true # 중복된 이름 문제 해결 - sudo docker run -d -p 8080:8080 --name server ${{ secrets.DOCKER_USERNAME }}/hero-alignlab-api + sudo docker run -d -p 8080:8080 --name server ${{ secrets.DOCKER_USERNAME }}/hero-alignlab-api:${{env.IMAGE_TAG}} sudo docker image prune -f