Update CD.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: CD | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '17' | |
distribution: 'zulu' | |
- name: Make application-test.properties | |
run: | | |
cd ./api/src/main/resources | |
touch ./application-api-production.properties | |
echo "${{ secrets.PROPERTIES_PRODUCTION }}" > ./application-api-production.properties | |
ls | |
shell: bash | |
- name: Run build | |
run: | | |
ls ./api/src/main/resources | |
./gradlew clean -Dspring.profiles.active=production api:build -x test | |
- name: Login to Docker Hub | |
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login --username "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin | |
- name: Build Docker image | |
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest ./api | |
- name: Push Docker image to Docker Hub | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest | |
- name: Deploy Docker image to remote server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.REMOTE_HOST }} | |
port: ${{ secrets.REMOTE_PORT }} | |
username: ${{ secrets.REMOTE_USERNAME }} | |
password: ${{ secrets.REMOTE_PASSWORD }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
script: | | |
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login --username "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest | |
docker rm -f hobbytalk-api | |
docker run -d -p 8080:8080 --name hobbytalk-api ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest |