Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cd: add test environment #66

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,29 @@ jobs:
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/mandacarubroker-api .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/mandacarubroker-api

deploy:
name: Deploy to Azure VM
deploy-test:
name: Deploy test environment to Azure VM
runs-on: ubuntu-latest
needs: push-to-registry
environment:
name: azure-test
url: https://test-api.mandacarubroker.com.br/docs
steps:
- name: Set up Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Save SSH private key to file
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > private_key
chmod 400 private_key

- name: Deploy to Azure VM and run Docker
run: ssh -o StrictHostKeyChecking=no -i private_key ${{ vars.AZURE_VM_USER }}@${{ vars.AZURE_VM_IP }} 'sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/mandacarubroker-api || true && sudo docker stop mandacarubroker-api || true && docker rm mandacarubroker-api || true && docker run --log-opt labels=applications,environment --restart unless-stopped --name mandacarubroker-api -e MANDACARU_POSTGRES_HOST=${{ secrets.MANDACARU_POSTGRES_HOST }} -e MANDACARU_POSTGRES_PORT=${{ secrets.MANDACARU_POSTGRES_PORT }} -e MANDACARU_POSTGRES_DB=${{ secrets.MANDACARU_POSTGRES_DB }} -e MANDACARU_POSTGRES_USER=${{ secrets.MANDACARU_POSTGRES_USER }} -e MANDACARU_POSTGRES_PASSWORD=${{ secrets.MANDACARU_POSTGRES_PASSWORD }} -e MANDACARU_SQL_INIT_MODE=${{ vars.MANDACARU_SQL_INIT_MODE }} -e MANDACARU_JWT_SECRET=${{ secrets.MANDACARU_JWT_SECRET }} -e MANDACARU_API_PORT=${{ vars.MANDACARU_API_PORT }} -p ${{ vars.MANDACARU_API_PORT }}:8080 -d ${{ secrets.DOCKERHUB_USERNAME }}/mandacarubroker-api'

deploy-production:
name: Deploy production environment to Azure VM
runs-on: ubuntu-latest
needs: push-to-registry
environment:
Expand Down
Loading