cd: log
파일들 EC2
폴더에서 볼 수 있도록 수정 (#79)
#12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: DEV) Push Docker Image And Deploy to EC2 | |
on: | |
push: | |
branches: [ "develop" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
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 | |
# 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 }} |