From bf91e590f7350783802bf70472a36f60c8d15f2c Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 31 Dec 2024 14:26:08 +0000 Subject: [PATCH] add manual workflow for deploying db --- .github/workflows/demo-db-deploy.yml | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/demo-db-deploy.yml diff --git a/.github/workflows/demo-db-deploy.yml b/.github/workflows/demo-db-deploy.yml new file mode 100644 index 0000000..4832314 --- /dev/null +++ b/.github/workflows/demo-db-deploy.yml @@ -0,0 +1,66 @@ +name: Deploy Demo Database +on: + workflow_dispatch: + inputs: + debug_enabled: + type: boolean + description: 'With build debug' + required: false + default: false +jobs: + demo_db_redeploy: + name: Redeploy Demo DB + runs-on: ubuntu-latest + container: + image: 'netdisco/netdisco:latest-backend' + options: '--user root --entrypoint /bin/ash' + volumes: + - '/home/runner/work:/github/workspace' + defaults: + run: + working-directory: /github/workspace/netdisco/netdisco + steps: + - name: Install base packages + run: apk add tmux bash curl sudo xz + - name: Install packages + run: apk add openssh-client gcc make musl-dev musl-obstack-dev python3 perl-dev unzip + - name: Install fake apt-get + run: echo 'if [ "$1" == "update" ]; then exec apk update; else exec apk add openssh-client xz; fi' > /usr/local/bin/apt-get && chmod +x /usr/local/bin/apt-get + + - name: Check out latest code + uses: actions/checkout@v1 + + - name: Fix owner of checkout + run: chown -R netdisco:netdisco /github/workspace/netdisco/netdisco + + - name: Reinitialise DB + env: + PGUSER: ${{ secrets.DEMO_PGUSER }} + PGPASSWORD: ${{ secrets.DEMO_PGPASSWORD }} + PGHOST: ${{ secrets.DEMO_PGHOST }} + PGDATABASE: ${{ secrets.DEMO_PGDATABASE }} + run: | + psql -c "DROP OWNED BY $PGUSER CASCADE" + psql -c "CREATE SCHEMA public" + curl -LO https://github.com/netdisco/netdisco2-demo/raw/master/netdisco2-demo-cumulus-clean.db.sql + psql -X -v ON_ERROR_STOP=0 -v ON_ERROR_ROLLBACK=on -d ${{ env.PGDATABASE }} -f netdisco2-demo-cumulus-clean.db.sql + + - name: Update schema + env: + NETDISCO_HOME: /github/workspace/netdisco/netdisco + POETRY_CACHE_DIR: /home/netdisco/python/cache/pypoetry + NETDISCO_DB_USER: ${{ secrets.DEMO_PGUSER }} + NETDISCO_DB_PASS: ${{ secrets.DEMO_PGPASSWORD }} + NETDISCO_DB_HOST: ${{ secrets.DEMO_PGHOST }} + NETDISCO_DB_NAME: ${{ secrets.DEMO_PGDATABASE }} + run: | + /home/netdisco/bin/localenv /github/workspace/netdisco/netdisco/bin/netdisco-db-deploy + /home/netdisco/bin/localenv /github/workspace/netdisco/netdisco/bin/netdisco-do stats -D + /home/netdisco/bin/localenv /github/workspace/netdisco/netdisco/bin/netdisco-do loadmibs -D + +# - name: Setup tmate session +# uses: mxschmitt/action-tmate@v3 +# if: always() && github.event.inputs.debug_dbdeploy_enabled == 'true' +# with: +# sudo: true +