diff --git a/.github/actions/erase-db/action.yml b/.github/actions/erase-db/action.yml new file mode 100644 index 00000000000..a5730905b87 --- /dev/null +++ b/.github/actions/erase-db/action.yml @@ -0,0 +1,35 @@ +name: 'Erase dspace db' +description: 'CI/CD Erase db' + +inputs: + INSTANCE: + description: 'port suffix' + required: true + type: string + NAME: + description: 'docker compose project name' + required: true + type: string + +runs: + using: "composite" + steps: + + - name: stop and remove containers + shell: bash + env: + INSTANCE: ${{ inputs.INSTANCE }} + run: | + docker stop dspacesolr$INSTANCE dspacedb$INSTANCE dspace$INSTANCE dspace-angular$INSTANCE || true + + - name: remove volumes + if: '!cancelled()' + shell: bash + env: + NAME: ${{ inputs.NAME }} + run: | + # be sure to have INSTANCE set + if [[ "x${NAME}" != "dspace-" ]]; then + echo docker volume rm $(docker volume ls --filter name="${NAME}_" -q) || true + fi; + diff --git a/.github/actions/import-db/action.yml b/.github/actions/import-db/action.yml new file mode 100644 index 00000000000..66517c9343b --- /dev/null +++ b/.github/actions/import-db/action.yml @@ -0,0 +1,64 @@ +name: 'Import dspace db' +description: 'CI/CD import db' + +inputs: + DATADIR: + description: 'data dir with dump, icons' + required: true + type: string + INSTANCE: + description: 'port suffix' + required: true + type: string + +runs: + using: "composite" + steps: + + - name: info + shell: bash + run: | + docker ps -a + + - uses: actions/checkout@v4 + with: + repository: dataquest-dev/dspace-python-api + path: dspace-python-api + ref: 'refactor_jm' + + + - name: stop and remove containers + id: import + shell: bash + working-directory: dspace-python-api/scripts + env: + DATADIR: ${{ inputs.DATADIR }} + DB5PORT: 15432 + DB5NAME: dspace-import-db5 + DB7PORT: 543${{ inputs.INSTANCE }} + BEURL: http://dev-5.pc:8${{ inputs.INSTANCE }}/server/api/ + run: | + docker stop $DB5NAME || true + echo "=====" + echo Starting import DB + # create otherwise it will be created with root owner + cid=$(docker run -d --rm --name $DB5NAME -v $(pwd):/dq/scripts -v $DATADIR/dump:/dq/dump -p 127.0.0.1:$DB5PORT:5432 -e POSTGRES_DB=empty -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=dspace postgres /bin/bash -c "cd /dq/scripts && ./init.dspacedb5.sh") + echo "cid=$cid" >> $GITHUB_OUTPUT + sleep 10 + echo "=====" + docker logs $DB5NAME || true + echo "=====" + cd ../ + pip install -r requirements.txt || true + echo "=====" + cd ./src + # cleanup resume + rm __temp/resume/*.json || true + python3 repo_import.py --resume=false --config=backend.endpoint=$BEURL --config=db_dspace_7.port=$DB7PORT --config=db_dspace_5.port=$DB5PORT --config=db_utilities_5.port=$DB5PORT --config=input.datadir=$DATADIR/data/ --config=input.icondir=$DATADIR/icon/ + + - name: cleanup + shell: bash + run: | + docker stop ${{ steps.import.outputs.cid }} || true + if: ${{ always() }} + diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0877e1a490d..1ce7bb8123c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,6 +2,17 @@ name: Deploy DSpace on: + workflow_call: + inputs: + INSTANCE: + required: false + type: string + default: '*' + IMPORT: + required: false + default: true + type: boolean + workflow_dispatch: inputs: INSTANCE: @@ -54,32 +65,29 @@ jobs: export ENVFILE=$(pwd)/.env.dev-5 ./start.sh dspace-5 - pre-deploy-import: - if: github.event.inputs.INSTANCE == '*' || github.event.inputs.INSTANCE == '8' - uses: dataquest-dev/dspace-angular/.github/workflows/erase_db.yml@dtq-dev - with: - INSTANCE: '8' - deploy-import: if: github.event.inputs.INSTANCE == '*' || github.event.inputs.INSTANCE == '8' - needs: pre-deploy-import runs-on: dspace-dep-1 timeout-minutes: 5 env: INSTANCE: '8' + ENVFILE: /opt/dspace-envs/.env.dspace.imported.dev-5 steps: - uses: actions/checkout@v4 + - uses: ./.github/actions/erase-db + with: + INSTANCE: ${{ env.INSTANCE }} + NAME: 'dspace-${{ env.INSTANCE }}' + - name: deploy dspace-import on dev-5 working-directory: build-scripts/run/ run: | - ENVFILE=/opt/dspace-envs/.env.dspace.imported.dev-5 ./start.sh dspace-$INSTANCE + ./start.sh dspace-$INSTANCE /bin/bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://dev-5.pc:8$INSTANCE/server/api)" != "200" ]]; do sleep 5; done' - post-deploy-import: - if: (github.event.inputs.INSTANCE == '*' || github.event.inputs.INSTANCE == '8') && github.event.inputs.IMPORT != false - needs: deploy-import - uses: dataquest-dev/dspace-angular/.github/workflows/import.yml@dtq-dev - secrets: inherit - with: - INSTANCE: '8' + - uses: ./.github/actions/import-db + if: github.event.inputs.IMPORT != false + with: + INSTANCE: ${{ env.INSTANCE }} + DATADIR: /opt/dspace-data/clarin-dspace/ diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 508d5e543f3..46d04a54764 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -87,12 +87,7 @@ jobs: tags: ${{ steps.meta_build.outputs.tags }} labels: ${{ steps.meta_build.outputs.labels }} - - name: redeploy - if: '!cancelled()' - run: | - curl -H "Accept: application/vnd.github.everest-preview+json" \ - -H "Authorization: token ${{ secrets.DEPLOY_DEV5_GH_ACTION_DISPATCH }}" \ - --request POST \ - https://api.github.com/repos/dataquest-dev/\ - dspace-angular/actions/workflows/deploy.yml/dispatches \ - --data "{\"ref\":\"refs/heads/dtq-dev\"}" + deploy: + needs: docker + uses: dataquest-dev/dspace-angular/.github/workflows/deploy.yml@dtq-dev + secrets: inherit diff --git a/.github/workflows/erase_db.yml b/.github/workflows/erase_db.yml deleted file mode 100644 index 4de6b28cf3a..00000000000 --- a/.github/workflows/erase_db.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Erase database - -on: - workflow_call: - inputs: - INSTANCE: - required: true - type: string - workflow_dispatch: - inputs: - INSTANCE: - required: true - default: '5' - type: choice - options: - - '5' - - '8' - - -jobs: - recreate_db: - runs-on: dspace-dep-1 - timeout-minutes: 5 - env: - INSTANCE: ${{ inputs.INSTANCE }} - NAME: dspace-${{ inputs.INSTANCE }} - steps: - - - name: stop and remove containers - run: | - docker stop dspacesolr$INSTANCE dspacedb$INSTANCE dspace$INSTANCE dspace-angular$INSTANCE || true - docker rm dspacesolr$INSTANCE dspacedb$INSTANCE dspace$INSTANCE dspace-angular$INSTANCE || true - - - name: remove volumes - if: '!cancelled()' - run: | - # be sure to have INSTANCE set - if [[ "x${{ env.NAME }}" != "dspace-" ]]; then - docker volume rm $(docker volume ls --filter name="${{ env.NAME }}_" -q) || true - fi; diff --git a/.github/workflows/import.yml b/.github/workflows/import.yml index 0c08c376489..98dfd268b71 100644 --- a/.github/workflows/import.yml +++ b/.github/workflows/import.yml @@ -1,11 +1,6 @@ name: Import DSpace v5 on: - workflow_call: - inputs: - INSTANCE: - required: true - type: string workflow_dispatch: inputs: INSTANCE: @@ -21,42 +16,20 @@ jobs: steps: - uses: actions/checkout@v4 - with: - repository: dataquest-dev/dspace-python-api - path: dspace-python-api - ref: 'refactor_jm' - - name: info - run: | - docker ps -a + - uses: ./.github/actions/erase-db + with: + INSTANCE: ${{ env.INSTANCE }} + NAME: 'dspace-${{ env.INSTANCE }}' - name: deploy dspace-import on dev-5 - id: import - env: - DATADIR: /opt/dspace-data/clarin-dspace/ - working-directory: dspace-python-api/scripts + working-directory: build-scripts/run/ run: | - docker stop dspace-import-db5 || true - echo "=====" - echo Starting import DB - export DB5PORT=15432 - # create otherwise it will be created with root owner - cid=$(docker run -d --rm --name dspace-import-db5 -v $(pwd):/dq/scripts -v $DATADIR/dump:/dq/dump -p 127.0.0.1:$DB5PORT:5432 -e POSTGRES_DB=empty -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=dspace postgres /bin/bash -c "cd /dq/scripts && ./init.dspacedb5.sh") - echo "cid=$cid" >> $GITHUB_OUTPUT - sleep 10 - echo "=====" - docker logs dspace-import-db5 || true - echo "=====" - cd ../ - pip install -r requirements.txt || true - echo "=====" - cd ./src - # cleanup resume - rm __temp/resume/*.json || true - python3 repo_import.py --resume=false --config=backend.endpoint=http://dev-5.pc:88/server/api/ --config=db_dspace_7.port=5438 --config=db_dspace_5.port=$DB5PORT --config=db_utilities_5.port=$DB5PORT --config=input.datadir=$DATADIR/data/ --config=input.icondir=$DATADIR/icon/ + ENVFILE=/opt/dspace-envs/.env.dspace.imported.dev-5 ./start.sh dspace-$INSTANCE + /bin/bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://dev-5.pc:8$INSTANCE/server/api)" != "200" ]]; do sleep 5; done' - - name: cleanup - run: | - docker stop ${{ steps.import.outputs.cid }} || true - if: ${{ always() }} - + - uses: ./.github/actions/import-db + if: github.event.inputs.IMPORT != false + with: + INSTANCE: ${{ env.INSTANCE }} + DATADIR: /opt/dspace-data/clarin-dspace/