From c00af20d2c547943f1e65de6752abb1d95cebc9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bournhonesque?= Date: Fri, 15 Dec 2023 14:59:38 +0100 Subject: [PATCH] chore: add deployment config --- .github/workflows/deploy.yml | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000000..66630b7ec6f --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,68 @@ +name: Deploy project + +on: + push: + branches: + - main + - deploy-* + - add-auto-deploy + tags: + - v*.*.* + + +# Note on secrets used for connection +# They are configured as environment secrets +# HOST is the internal ip of VM containing docker +# PROXY_HOST is the host of VMs +# USERNAME is the user used for operations +# SSH_PRIVATE_KEY is the private key (shared between VM and host) + +jobs: + deploy: + runs-on: ubuntu-latest + strategy: + matrix: + env: + # Note: env is also the name of the directory on the server + - ${{ startsWith(github.ref, 'refs/tags/v') && 'open-prices-org' || 'open-prices-net' }} + environment: ${{ matrix.env }} + concurrency: ${{ matrix.env }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "yarn" + + - name: Install dependencies + run: yarn install --immutable + + - name: Build + run: yarn build-staging + + # Deploy + - name: Set common variables + run: | + # We use the prod oauth server for all environments + echo "SSH_PROXY_HOST=ovh1.openfoodfacts.org" >> $GITHUB_ENV + echo "SSH_USERNAME=off" >> $GITHUB_ENV + - name: Set various variable for staging (net) deployment + if: matrix.env == 'open-prices-net' + run: | + echo "SSH_HOST=10.1.0.200" >> $GITHUB_ENV + - name: Set various variable for production deployment + if: matrix.env == 'open-prices-org' + run: | + echo "SSH_HOST=10.1.0.201" >> $GITHUB_ENV + + - name: Copy dist via scp + uses: appleboy/scp-action@master + with: + host: ${{ env.SSH_HOST }} + username: ${{ env.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + proxy_host: ${{ env.SSH_PROXY_HOST }} + proxy_username: ${{ env.SSH_USERNAME }} + proxy_key: ${{ secrets.SSH_PRIVATE_KEY }} + source: "dist" + target: "/tmp/open-prices-dist" \ No newline at end of file