Skip to content

Commit

Permalink
use composite actions instead of reusable workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jm committed Nov 8, 2023
1 parent 955dbba commit 1c06f92
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 103 deletions.
35 changes: 35 additions & 0 deletions .github/actions/erase-db/action.yml
Original file line number Diff line number Diff line change
@@ -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;
64 changes: 64 additions & 0 deletions .github/actions/import-db/action.yml
Original file line number Diff line number Diff line change
@@ -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() }}

38 changes: 23 additions & 15 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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/
13 changes: 4 additions & 9 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 0 additions & 40 deletions .github/workflows/erase_db.yml

This file was deleted.

51 changes: 12 additions & 39 deletions .github/workflows/import.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Import DSpace v5

on:
workflow_call:
inputs:
INSTANCE:
required: true
type: string
workflow_dispatch:
inputs:
INSTANCE:
Expand All @@ -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/

0 comments on commit 1c06f92

Please sign in to comment.