Update gradle.yml #12
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: Build and Deploy | |
on: | |
push: | |
branches: [ "main" ] | |
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: 'temurin' | |
- name: Build with Gradle | |
run: ./gradlew assemble | |
- name: Build and push Docker image | |
run: | | |
# Log in to Docker Hub | |
echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
# Build the Docker image with the 'latest' tag | |
docker build -t ${{ secrets.DOCKERHUB_CONTAINERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }} . | |
# Push the Docker image to Docker Hub | |
docker push ${{ secrets.DOCKERHUB_CONTAINERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest | |
- name: Deploy to server | |
uses: appleboy/ssh-action@master | |
with: | |
host: 35.216.60.77 | |
username: km25352535 | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: 22 | |
script: | | |
# Log in to Docker Hub | |
echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
# Pull the latest Docker image | |
sudo docker pull ${{ secrets.DOCKERHUB_CONTAINERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest | |
# Stop and remove the existing container if it exists | |
sudo docker ps -q -f name=speech2 | xargs -r sudo docker stop | |
sudo docker ps -a -q -f name=speech2 | xargs -r sudo docker rm | |
# Run the new container with environment variables | |
sudo docker run -d \ | |
-p 8080:8080 \ | |
--name speech2 \ | |
-e GOOGLE_CLOUD_DATABASE=${{ secrets.GOOGLE_CLOUD_DATABASE }} \ | |
-e GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} \ | |
-e GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} \ | |
-e KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }} \ | |
-e KAKAO_CLIENT_SECRET=${{ secrets.KAKAO_CLIENT_SECRET }} \ | |
-e GITHUB_CLIENT_ID=${{ secrets.GITHUB_CLIENT_ID }} \ | |
-e GITHUB_CLIENT_SECRET=${{ secrets.GITHUB_CLIENT_SECRET }} \ | |
-e API_VOICE_TO_TEXT_URL=${{ secrets.API_VOICE_TO_TEXT_URL }} \ | |
-e API_VOICE_TO_TEXT_ACCESS_KEY=${{ secrets.API_VOICE_TO_TEXT_ACCESS_KEY }} \ | |
-e API_VOICE_TO_LANGUAGE_CODE=${{ secrets.API_VOICE_TO_LANGUAGE_CODE }} \ | |
-e API_VOICE_TO_SCORE=${{ secrets.API_VOICE_TO_SCORE }} \ | |
-e SPEECH_FLOW_API_KEY_ID=${{ secrets.SPEECH_FLOW_API_KEY_ID }} \ | |
-e SPEECH_FLOW_API_KEY_SECRET=${{ secrets.SPEECH_FLOW_API_KEY_SECRET }} \ | |
-e SPEECH_FLOW_LANG=${{ secrets.SPEECH_FLOW_LANG }} \ | |
-e SPEECH_FLOW_RESULT_TYPE=${{ secrets.SPEECH_FLOW_RESULT_TYPE }} \ | |
-e JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} \ | |
${{ secrets.DOCKERHUB_CONTAINERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest | |
# Clean up old Docker images | |
sudo docker image prune -f |