Skip to content

#123 - 레디스를 통한 조회수 및 인기 아카이브 관리 구현 (#124) #59

#123 - 레디스를 통한 조회수 및 인기 아카이브 관리 구현 (#124)

#123 - 레디스를 통한 조회수 및 인기 아카이브 관리 구현 (#124) #59

Workflow file for this run

name: DEV) Push Docker Image And Deploy to EC2
on:
push:
branches: [ "develop" ]
permissions:
contents: read
jobs:
backend-docker-build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch || github.ref }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
- name: Set up yml ec2 dev file
env:
YAML_SECRET: ${{ secrets.YAML_EC2_DEV }}
YAML_DIR: src/main/resources
YAML_FILE_NAME: application-ec2-dev.yml
run: |
echo $YAML_SECRET | base64 --decode > $YAML_DIR/$YAML_FILE_NAME
echo "YAML_SECRET has been decoded and saved to $YAML_DIR/$YAML_FILE_NAME"
- name: Set up yml secrets file
env:
YAML_SECRET: ${{ secrets.SECRET_YAML }}
YAML_DIR: src/main/resources
YAML_FILE_NAME: application-secret.yml
run: |
echo $YAML_SECRET | base64 --decode > $YAML_DIR/$YAML_FILE_NAME
echo "YAML_SECRET has been decoded and saved to $YAML_DIR/$YAML_FILE_NAME"
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Get Short SHA
id: short_sha
run: |
echo "::set-output name=sha_short::$(echo ${{ github.sha }} | head -c 7)"
echo "Short SHA: ${{ steps.short_sha.outputs.sha_short }}"
- name: Print branch & tag information
run: |
echo "Current branch: ${{ github.event.inputs.branch || github.ref }}"
echo "Current tag: ${{ steps.short_sha.outputs.sha_short }}"
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: Docker Login and Push
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
DOCKER_IMAGE_TAG: palettee-server:${{ steps.short_sha.outputs.sha_short }}
run: |
echo $DOCKER_HUB_PASSWORD | docker login -u $DOCKER_HUB_USERNAME --password-stdin
docker build -t $DOCKER_IMAGE_TAG .
docker tag $DOCKER_IMAGE_TAG $DOCKER_HUB_USERNAME/$DOCKER_IMAGE_TAG
docker push $DOCKER_HUB_USERNAME/$DOCKER_IMAGE_TAG
# - name: Show CWD Properties
# run: |
# echo "Current directory : `pwd`"
# ls -al
# echo 'tree ./'
# tree ./ -a
#
# - name: ✨ DockerHub에 로그인
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_PASSWORD }}
#
# - name: ✨ Docker Image 빌드 후 DockerHub에 Push
# uses: docker/build-push-action@v4
# with:
# context: .
# file: ./Dockerfile
# push: true
# platforms: linux/arm64
# tags: dksxogh902318/palettee-server:latest
# Deploy to EC2
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_IP }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.EC2_PEM_KEY }}
script: |
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/palettee-server:${{ steps.short_sha.outputs.sha_short }}
docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/palettee-server:${{ steps.short_sha.outputs.sha_short }} palettee-server
docker rm -f palettee-server || true
docker run -d --name palettee-server \
-e TZ=Asia/Seoul -e SPRING_PROFILES_ACTIVE=ec2-dev \
-v ~/palettee-service-logs:/home/palettee-service-logs \
-p 8081:8081 ${{ secrets.DOCKER_HUB_USERNAME }}/palettee-server:${{ steps.short_sha.outputs.sha_short }}
#
# backend-docker-pull-and-run:
# runs-on: [self-hosted, dev]
# if: ${{ needs.backend-docker-build-and-push.result == 'success' }}
# needs: [ backend-docker-build-and-push ]
# steps:
# - name: ✨ 배포 스크립트 실행
# run: |
# bash /home/ubuntu/deploy.sh