Update gradle.yml #8
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 to AWS EC2 | |
on: | |
push: | |
branches: | |
- test | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Set up Docker Environment | |
run: | | |
touch ./.env | |
echo "DB_CONNECTION_URL=${{ secrets.MYSQL_DB_URL }}" >> .env | |
echo "USER_NAME=${{ secrets.DB_USER }}" >> .env | |
echo "PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env | |
echo "FILE_STORAGE_DIR=${{ secrets.FILE_PATH }}" >> .env | |
shell: bash | |
# Gradle build | |
- name: Build with Gradle | |
run: ./gradlew bootJar | |
- name: web docker build and push | |
run: | | |
docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t ${{ secrets.DOCKER_REPO }}/planit-server . | |
docker push ${{ secrets.DOCKER_REPO }}/planit-server | |
- name: Deploy to EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
script: | | |
sudo docker rm -f $(docker ps -qa) | |
sudo docker pull ${{ secrets.DOCKER_REPO }}/planit-server | |
docker-compose up -d | |
docker image prune -f |