[#1] 개발서버 ci 스크립트 작성 및 배포 자동화 구축 #1
Workflow file for this run
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: cd-dev | |
on: | |
push: | |
branches: [ "dev" ] | |
pull_request: | |
branches: [ "dev" ] | |
jobs: | |
deploy-to-ec2: | |
environment: dev | |
runs-on: ubuntu-latest | |
steps: | |
- name: Github Repository Checkout | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
token: ${{ secrets.ACCESS_TOKEN }} | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@v2 | |
with: | |
arguments: build | |
- name: Docker Emulator Setting | |
uses: docker/setup-qemu-action@v2 | |
- name: Docker BuildX Setting | |
uses: docker/setup-buildx-action@v2 | |
- name: Container Registry Login | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }} | |
password: ${{ secrets.ACCESS_TOKEN }} | |
- name: Docker Image Build and Push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: ${{ secrets.CONTAINER_REGISTRY_IMAGE_TAG }} | |
platforms: linux/arm64 | |
- name: Copy Deployment Files to EC2 | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.EC2_INSTANCE_HOST }} | |
username: ${{ secrets.EC2_INSTANCE_USERNAME }} | |
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | |
source: './deploy/dev/*' | |
target: '~/pickple/deploy' | |
strip_components: 1 | |
- name: Docker Container Run | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_INSTANCE_HOST }} | |
username: ${{ secrets.EC2_INSTANCE_USERNAME }} | |
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | |
script: | | |
docker pull ${{ secrets.CONTAINER_REGISTRY_IMAGE_TAG }} | |
cd ~/pickple/deploy/dev | |
docker-compose -p pickple-dev down | |
docker-compose -p pickple-dev up -d | |
docker image prune -f |