Skip to content

Deploy

Deploy #71

Workflow file for this run

name: Deploy
on:
push:
branches: [main]
workflow_dispatch:
jobs:
deploy-staging:
name: Deploy - staging
runs-on: ubuntu-latest
timeout-minutes: 15
environment:
name: staging
steps:
- uses: actions/checkout@v3
- name: Set up SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_PRIVATE_KEY" > ./deploy.key
sudo chmod 600 ./deploy.key
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
shell: bash
env:
SSH_PRIVATE_KEY: ${{secrets.SSH_MACHINE_USER_PRIVATE_KEY}}
SSH_HOST: ${{ secrets.SSH_HOST_STAGING }}
- name: Deploy to staging
run: ssh -i ./deploy.key www-data@$SSH_HOST 'python3 /opt/scripts/app-deploy-release/deploy.py /opt/git/releases/annuaire-entreprises-api-proxy https://github.com/annuaire-entreprises-data-gouv-fr/api-proxy.git api-proxy --version main --versions_to_keep=5 1> >(tee --append /var/log/deploy_annuaire-entreprises-api-proxy)'
env:
SSH_HOST: ${{ secrets.SSH_HOST_STAGING }}
- name: Notify staging failure only
if: failure()
uses: ./.github/actions/notify
with:
message: '🚨 ${{ github.event.repository.name }} : deploy to staging failed'
hook: ${{ secrets.TCHAP_HOOK }}
id: ${{ secrets.TCHAP_ROOM_ID }}
deploy-production:
name: Deploy - production
runs-on: ubuntu-latest
needs: [deploy-staging]
environment:
name: production
steps:
- uses: actions/checkout@v3
- name: Set up SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_PRIVATE_KEY" > ./deploy.key
sudo chmod 600 ./deploy.key
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
shell: bash
env:
SSH_PRIVATE_KEY: ${{secrets.SSH_MACHINE_USER_PRIVATE_KEY}}
SSH_HOST: ${{ secrets.SSH_HOST_PRODUCTION }}
- name: Deploy to production
run: ssh -i ./deploy.key www-data@$SSH_HOST 'python3 /opt/scripts/app-deploy-release/deploy.py /opt/git/releases/annuaire-entreprises-api-proxy https://github.com/annuaire-entreprises-data-gouv-fr/api-proxy.git api-proxy --version main --versions_to_keep=5 1> >(tee --append /var/log/deploy_annuaire-entreprises-api-proxy)'
env:
SSH_HOST: ${{ secrets.SSH_HOST_PRODUCTION }}
- name: Notify staging failure only
if: failure()
uses: ./.github/actions/notify
with:
message: '🚨 ${{ github.event.repository.name }} : deploy to production failed'
hook: ${{ secrets.TCHAP_HOOK }}
id: ${{ secrets.TCHAP_ROOM_ID }}
- name: Notify deploy succes
if: success()
uses: ./.github/actions/notify
with:
message: '✅ ${{ github.event.repository.name }} : successfully deploy to staging & production'
hook: ${{ secrets.TCHAP_HOOK }}
id: ${{ secrets.TCHAP_ROOM_ID }}