feat: implement portfolio api (#93) #231
Workflow file for this run
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 | |
- develop | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
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 and copy docker-compose.yml to server | |
run: | | |
cd ./api-server | |
sudo docker build --build-arg DEPENDENCY=build/dependency -t ${{ secrets.NCP_CONTAINER_REGISTRY_API }}/payout-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 }}/payout-api | |
cd ../batch | |
sudo docker build --build-arg DEPENDENCY=build/dependency -t ${{ secrets.NCP_CONTAINER_REGISTRY_BATCH }}/payout-batch --platform linux/amd64 . | |
sudo docker login ${{ secrets.NCP_CONTAINER_REGISTRY_BATCH }} -u ${{ secrets.NCP_ACCESS_KEY }} -p ${{ secrets.NCP_SECRET_KEY }} | |
sudo docker push ${{ secrets.NCP_CONTAINER_REGISTRY_BATCH }}/payout-batch | |
cd .. | |
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 }} | |
sshpass -p ${{ secrets.API_SERVER_PASSWORD }} scp -o StrictHostKeyChecking=no ./nginx/nginx.conf ${{ secrets.API_SERVER_USERNAME }}@${{ secrets.API_SERVER_HOST }}:${{ secrets.DOCKER_COMPOSE_PATH }} | |
sshpass -p ${{ secrets.API_SERVER_PASSWORD }} scp -o StrictHostKeyChecking=no ./deploy.sh ${{ 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/ssh-action@master | |
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 FMP_API_KEY=${{ secrets.FMP_API_KEY }} | |
export NINJAS_API_KEY=${{ secrets.NINJAS_API_KEY }} | |
export NCP_CONTAINER_REGISTRY_API=${{ secrets.NCP_CONTAINER_REGISTRY_API }} | |
export NCP_CONTAINER_REGISTRY_BATCH=${{ secrets.NCP_CONTAINER_REGISTRY_BATCH }} | |
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 }}/payout-api | |
sudo docker login ${{ secrets.NCP_CONTAINER_REGISTRY_BATCH }} -u ${{ secrets.NCP_ACCESS_KEY }} -p ${{ secrets.NCP_SECRET_KEY }} | |
sudo docker pull ${{ secrets.NCP_CONTAINER_REGISTRY_BATCH }}/payout-batch | |
bash ${{ secrets.DOCKER_COMPOSE_PATH }}/deploy.sh | |
docker image prune -f |