test: cd 테스트 #2
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: Backend CD | |
on: | |
push: | |
branches: | |
- main | |
- feat/#6-ci-cd | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Execute Gradle build | |
run: ./gradlew clean build | |
- name: Set up Docker Build | |
uses: docker/setup-buildx-action@v2 | |
- name: Docker build and push to NCP container registry | |
run: | | |
sudo docker build --build-arg DEPENDENCY=build/dependency -t ${{ secrets.NCP_CONTAINER_REGISTRY_API }}/goalpanzi-api --platform linux/amd64 . | |
sudo docker login ${{ secrets.NCP_CONTAINER_REGISTRY_API }} -u ${{ secrets.NCP_ACCESS_KEY }} -p ${{ secrets.NCP_SECRET_KEY }} | |
sudo docker push ${{ secrets.NCP_CONTAINER_REGISTRY_API }}/goalpanzi-api | |
sshpass -p ${{ secrets.API_SERVER_PASSWORD }} scp -o StrictHostKeyChecking=no ./docker-compose.yml ${{ secrets.API_SERVER_USERNAME }}@${{ secrets.API_SERVER_HOST }}:${{ secrets.DOCKER_COMPOSE_PATH }} | |
shell: bash | |
deploy-to-server: | |
name: Connect api server ssh and pull from container registry | |
needs: build-and-push | |
runs-on: ubuntu-latest | |
steps: | |
## docker compose up | |
- name: Deploy to api server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.API_SERVER_HOST }} | |
username: ${{ secrets.API_SERVER_USERNAME }} | |
password: ${{ secrets.API_SERVER_PASSWORD }} | |
script: | | |
export DB_HOSTNAME=${{ secrets.DB_HOSTNAME }} | |
export DB_PORT=${{ secrets.DB_PORT }} | |
export DB_DATABASE=${{ secrets.DB_DATABASE }} | |
export DB_USERNAME=${{ secrets.DB_USERNAME }} | |
export DB_PASSWORD=${{ secrets.DB_PASSWORD }} | |
export OAUTH_APPLE_CLIENT_ID=${{ secrets.OAUTH_APPLE_CLIENT_ID }} | |
export NCP_CONTAINER_REGISTRY_API=${{ secrets.NCP_CONTAINER_REGISTRY_API }} | |
export NCP_CONTAINER_REGISTRY_BATCH=${{ secrets.NCP_CONTAINER_REGISTRY_BATCH }} | |
sudo docker rm -f $(docker ps -qa) | |
sudo docker login ${{ secrets.NCP_CONTAINER_REGISTRY_API }} -u ${{ secrets.NCP_ACCESS_KEY }} -p ${{ secrets.NCP_SECRET_KEY }} | |
sudo docker pull ${{ secrets.NCP_CONTAINER_REGISTRY_API }}/goalpanzi-api | |
docker-compose -f ${{ secrets.DOCKER_COMPOSE_PATH }}/docker-compose.yml up -d | |
docker image prune -f |