Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Sep 18, 2023
0 parents commit 9e2ba2f
Show file tree
Hide file tree
Showing 14 changed files with 315 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .env.dataverse
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POSTGRES_VERSION=13
DATAVERSE_DB_USER=dataverse
SOLR_VERSION=8.11.1
DATAVERSE_BOOTSTRAP_TIMEOUT=5m
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
19 changes: 19 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on: [push]

jobs:
custom_test:
runs-on: ubuntu-latest
name: Test the action
env:
PORT: 8080
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
- name: Run Dataverse Action
uses: ./
with:
create-dv: true
- name: Check Dataverse Setup
run: |
echo $(curl http://localhost:8080/api/info/version) && \
echo $(curl http://localhost:8080/api/metadatablocks)
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Jan Range

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Dataverse Configbaker Action

This GitHub Action serves as a powerful tool to effortlessly create a functional Dataverse instance, enabling developers to run comprehensive tests and perform other critical tasks within their GitHub CI workflows.

## Usage

In order to use this action you need to add the following to your workflow file:

```yaml
name: Test Dataverse
uses: gdcc/dataverse-action@main
with:
create-dv: true
```
### Parameters
* `create-dv`: Whether to create a Dataverse to add data to or not. Default: `true`
* `port`: The port to run the Dataverse instance on. Default: `8080`

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
25 changes: 25 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: dv-configbaker
description: |
"This GitHub Action serves as a powerful tool to create a functional Dataverse instance, enabling developers to run tests and perform other critical tasks within their GitHub CI workflows."
inputs:
create-dv:
description: "Whether or not to create an example Dataverse"
required: true
runs:
using: "composite"
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
- name: Setup Dataverse
run: ${{ github.action_path }}/scripts/dataverse_setup.sh
shell: bash
- name: Check API Status
run: ${{ github.action_path }}/scripts/check_api_status.sh
shell: bash
- name: Retrieve API Token
run: ${{ github.action_path }}/scripts/get_api_token.sh
shell: bash
- name: Create Dataverse
run: ${{ github.action_path }}/scripts/create_dataverse.sh
shell: bash

15 changes: 15 additions & 0 deletions assets/dataverse-complete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Scientific Research",
"alias": "science",
"dataverseContacts": [
{
"contactEmail": "[email protected]"
},
{
"contactEmail": "[email protected]"
}
],
"affiliation": "Scientific Research University",
"description": "We do all the science.",
"dataverseType": "LABORATORY"
}
8 changes: 8 additions & 0 deletions assets/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"firstName": "Lisa",
"lastName": "Simpson",
"userName": "lsimpson",
"affiliation": "Springfield",
"position": "Student",
"email": "[email protected]"
}
104 changes: 104 additions & 0 deletions docker-compose-dataverse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
version: '2.4'

services:
dataverse:
container_name: 'dataverse'
hostname: dataverse
image: gdcc/dataverse:alpha
restart: on-failure
user: payara
environment:
- DATAVERSE_DB_HOST=postgres
- DATAVERSE_DB_PASSWORD=secret
- DATAVERSE_DB_USER=${DATAVERSE_DB_USER}
# to get HarvestingServerIT to pass
- dataverse_oai_server_maxidentifiers=2
- dataverse_oai_server_maxrecords=2
ports:
- '8080:8080'
networks:
- dataverse
depends_on:
- postgres
- solr
tmpfs:
- /dumps:mode=770,size=2052M,uid=1000,gid=1000
- /tmp:mode=770,size=2052M,uid=1000,gid=1000
mem_limit: 2147483648 # 2 GiB
mem_reservation: 1024m
privileged: false

dataverse_bootstrap:
container_name: 'dataverse_bootstrap'
image: gdcc/configbaker:alpha
restart: 'no'
environment:
- TIMEOUT=${DATAVERSE_BOOTSTRAP_TIMEOUT}
command:
- bootstrap.sh
- dev
networks:
- dataverse

postgres:
container_name: 'postgres'
hostname: postgres
image: postgres:${POSTGRES_VERSION}
restart: on-failure
environment:
- POSTGRES_USER=${DATAVERSE_DB_USER}
- POSTGRES_PASSWORD=secret
ports:
- '5432:5432'
networks:
- dataverse

solr_initializer:
container_name: 'solr_initializer'
image: gdcc/configbaker:alpha
restart: 'no'
command:
- sh
- -c
- 'fix-fs-perms.sh solr && cp -a /template/* /solr-template'
volumes:
- ${RUNNER_TEMP}/solr/data:/var/solr
- ${RUNNER_TEMP}/solr/conf:/solr-template

solr:
container_name: 'solr'
hostname: 'solr'
image: solr:${SOLR_VERSION}
depends_on:
- solr_initializer
restart: on-failure
ports:
- '8983:8983'
networks:
- dataverse
command:
- 'solr-precreate'
- 'collection1'
- '/template'
volumes:
- ${RUNNER_TEMP}/solr/data:/var/solr
- ${RUNNER_TEMP}/solr/conf:/template

smtp:
container_name: 'smtp'
hostname: 'smtp'
image: maildev/maildev:2.0.5
restart: on-failure
expose:
- '25' # smtp server
environment:
- MAILDEV_SMTP_PORT=25
- MAILDEV_MAIL_DIRECTORY=/mail
networks:
- dataverse
tmpfs:
- /mail:mode=770,size=128M,uid=1000,gid=1000

networks:
dataverse:
driver: bridge
7 changes: 7 additions & 0 deletions scripts/check_api_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
echo "πŸš€ Health checks"

./scripts/wait_for_url.sh \
"http://localhost:8080/api/info/version" \
"http://localhost:8080/api/metadatablocks"

echo -e "βœ… Health checks done\n"
6 changes: 6 additions & 0 deletions scripts/create_dataverse.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
echo "πŸš€ Creating Test Dataverse"

curl -H "X-Dataverse-key:$API_TOKEN" \
--silent \
-X POST "localhost:8080/api/dataverses/1" \
--upload-file ./assets/dataverse-complete.json
18 changes: 18 additions & 0 deletions scripts/dataverse_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

echo "πŸš€ Setting up Dataverse"

# Create host address
export HOST="http://localhost:8080"

# Clone the dataverse repository and cd into it
git clone -b develop https://github.com/IQSS/dataverse.git

cd dataverse

# Run API containers
docker compose -f ../docker-compose-dataverse.yml \
--env-file ../.env.dataverse \
up -d --quiet-pull && echo -e "βœ… Dataverse containers are up\n"

cd ../
30 changes: 30 additions & 0 deletions scripts/get_api_token.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

echo "πŸš€ Retrieving API Token"

# Set variables
export BUILTIN_USERS_KEY="burrito"
export PASSWORD="TEST123!"
export HOST="http://localhost:8080"

# Set the builtin user key
curl -X PUT \
-o /dev/null \
-d $BUILTIN_USERS_KEY \
--silent \
$HOST/api/admin/settings/BuiltinUsers.KEY &&
echo "β”œβ”€ BuiltinUsers.KEY set"

# Create a user and receive the API Token
curl -d @./assets/user.json \
-o ./user_data.json \
-H "Content-type:application/json" \
--silent \
"$HOST/api/builtin-users?password=$PASSWORD*&key=$BUILTIN_USERS_KEY" &&
echo "β”œβ”€ User created"

# Retrieve the API Token and put into env variable
API_TOKEN=$(echo $(cat ./user_data.json) | jq -r '.data.apiToken')
echo "API_TOKEN=$API_TOKEN" >>$GITHUB_ENV

echo -e "βœ… API Token added to environment\n"
33 changes: 33 additions & 0 deletions scripts/wait_for_url.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

##############################################################################################
#
# Credits: https://gist.github.com/eisenreich/195ab1f05715ec86e300f75d007d711c
#
# Wait for URLs until return HTTP 200
#
# - Just pass as many urls as required to the script - the script will wait for each, one by one
#
# Example: ./wait_for_urls.sh "${MY_VARIABLE}" "http://192.168.56.101:8080"
##############################################################################################

wait-for-url() {
echo -e "β”œβ”€ Waiting for ${1}"
timeout --foreground -s TERM 280s bash -c \
'while [[ "$(curl -s -o /dev/null -m 3 -L -w ''%{http_code}'' ${0})" != "200" ]];\
do sleep 20;\
done' ${1}
local TIMEOUT_RETURN="$?"
if [[ "${TIMEOUT_RETURN}" == 0 ]]; then
echo -e "β”œβ”€ Endpoint is up"
return
elif [[ "${TIMEOUT_RETURN}" == 120000 ]]; then
echo "β”œβ”€ Timeout: ${1} -> EXIT"
exit "${TIMEOUT_RETURN}"
fi

}

for var in "$@"; do
wait-for-url "$var"
done

0 comments on commit 9e2ba2f

Please sign in to comment.