[develop-v2] main merge #33
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 EC2 | |
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 }}/neverland . | |
- name: Docker Hub push | |
run: docker push ${{ secrets.DOCKER_USERNAME }}/neverland | |
# 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 }}/neverland | |
docker stop $(docker ps -qa) | |
docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/neverland | |
docker rm $(docker ps --filter 'status=exited' -qa) | |
docker image prune -f |