Merge pull request #2 from jjekrrq/main #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: Skhuthon_0th_TEAM9 | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
Build: | |
name: Build application | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up JDK 19 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Grant execute permission for gradlew | |
run: chmod +x Skhuthon_0th_TEAM9/gradlew | |
- name: Sign in Dockerhub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{secrets.DOCKER_USERNAME}} | |
password: ${{secrets.DOCKER_PASSWORD}} | |
- name: Build Docker image with Gradle Buildpack | |
env: | |
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}} | |
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} | |
working-directory: ./Skhuthon_0th_TEAM9 | |
run: ./gradlew bootBuildImage --imageName=${{ secrets.DOCKER_REPOSITORY }} | |
- name: Docker push | |
run: | | |
docker tag ${{secrets.DOCKER_REPOSITORY}}:latest ${{secrets.DOCKER_USERNAME}}/${{secrets.DOCKER_REPOSITORY}}:latest | |
docker push ${{secrets.DOCKER_USERNAME}}/${{secrets.DOCKER_REPOSITORY}} | |
Deploy: | |
name: Deploy application | |
needs: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: SSH Remote connect and Docker | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{secrets.REMOTE_HOST}} | |
username: ${{secrets.REMOTE_SSH_ID}} | |
key: ${{secrets.REMOTE_SSH_KEY}} | |
port: ${{secrets.REMOTE_SSH_PORT}} | |
timeout: 40s | |
script: | | |
OLD_IMAGE=$(docker-compose ps -q | xargs docker inspect --format='{{.Image}}' | uniq) | |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | |
cd ${{secrets.REMOTE_DOCKER_PATH}} | |
docker-compose down | |
docker pull ${{secrets.DOCKER_USERNAME}}/${{secrets.DOCKER_REPOSITORY}} | |
docker-compose up -d | |