-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a1069d
commit 04a60fd
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
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 }}/haemo . | ||
- name: Docker Hub push | ||
run: docker push ${{ secrets.DOCKER_USERNAME }}/haemo | ||
|
||
# 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 }}/haemo | ||
docker stop $(docker ps -qa) | ||
docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/haemo | ||
docker rm $(docker ps --filter 'status=exited' -qa) | ||
docker image prune -f |