[feat] main branch pull request #85
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: CD with Gradle | |
on: | |
push: | |
branches: [ "main", "develop" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'oracle' | |
- name: Make env file | |
run: | | |
echo "${{ secrets.ENV }}" | base64 --decode > .env | |
- name: Make docker-compose file | |
run: | | |
echo "\n" >> ./docker-compose.yml | |
echo "${{ secrets.DOCKER_COMPOSE }}" | base64 --decode >> ./docker-compose.yml | |
echo "\n" >> ./docker-compose.yml | |
- name: Grant execute permission for gradlew | |
run: | | |
chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
- name: Docker Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Docker build & push to Docker repo | |
run: | | |
docker build -f Dockerfile -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO }} . | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO }} | |
- name: Deploy to server | |
uses: appleboy/ssh-action@master | |
id: deploy | |
with: | |
host: ${{ secrets.AWS_HOST }} | |
username: ubuntu | |
key: ${{ secrets.AWS_SSH_KEY }} | |
envs: GITHUB_SHA | |
script: | | |
sudo docker rm -f $(docker ps -qa) | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO }} | |
sudo docker-compose up -d --build | |
sudo docker image prune -f |