refactor: 실제 api와 클라이언트를 연결해본다 (#159) #1
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: deploy | |
on: | |
push: | |
branches: | |
- release/backend | |
jobs: | |
docker-build: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./backend | |
steps: | |
- name: Log in to Docker Hub | |
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
- 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: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew bootjar | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | |
with: | |
images: woowacarffeine/backend | |
- name: Build and push Docker image | |
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 | |
with: | |
context: . | |
file: ./backend/Dockerfile | |
push: true | |
platforms: linux/arm64 | |
tags: woowacarffeine/backend:latest | |
labels: ${{ steps.meta.outputs.labels }} | |
deploy: | |
runs-on: self-hosted | |
if: ${{ needs.docker-build.result == 'success' }} | |
needs: [ docker-build ] | |
steps: | |
- name: Join EC2 dev server | |
uses: appleboy/ssh-action@master | |
env: | |
JASYPT_KEY: ${{ secrets.JASYPT_KEY }} | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_KEY }} | |
port: ${{ secrets.SERVER_PORT }} | |
envs: JASYPT_KEY | |
script: | | |
sudo docker pull woowacarffeine/backend:latest | |
sudo docker stop backend || true | |
sudo docker run -d --rm -p 8080:8080 \ | |
-e "ENCRYPT_KEY=${{secrets.JASYPT_KEY}}" \ | |
--name backend \ | |
woowacarffeine/backend:latest | |
sudo docker image prune -f |