Skip to content

[develop] ์ฑŒ๋ฆฐ์ง€ ์ธ์ฆ์ฝ”๋“œ ๋ฐœ๊ธ‰ API ๊ตฌํ˜„ #35

[develop] ์ฑŒ๋ฆฐ์ง€ ์ธ์ฆ์ฝ”๋“œ ๋ฐœ๊ธ‰ API ๊ตฌํ˜„

[develop] ์ฑŒ๋ฆฐ์ง€ ์ธ์ฆ์ฝ”๋“œ ๋ฐœ๊ธ‰ API ๊ตฌํ˜„ #35

Workflow file for this run

name: Deploy EC2
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# create application.yml
- name: create application.yml
run: |
mkdir ./src/main/resources
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION_FILE }}" > ./application.yml
shell: bash
# grant permisson
- name: Grant permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle Wrapper
run: ./gradlew build -x test
# docker
- name: Docker hub login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker image build
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/wecare .
- name: Docker Hub push
run: docker push ${{ secrets.DOCKER_USERNAME }}/wecare
# deploy
- name: Deploy to Instance
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.AWS_USERNAME }}
key: ${{ secrets.AWS_PRIVATEKEY }}
script: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker pull ${{ secrets.DOCKER_USERNAME }}/wecare
docker stop $(docker ps -qa)
docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/wecare
docker rm $(docker ps --filter 'status=exited' -qa)
docker image prune -f