-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP - 13 dockerize #14
Open
poikilotherm
wants to merge
6
commits into
IQSS:master
Choose a base branch
from
poikilotherm:13-dockerize
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8cf4c98
Add Dockerfile for fast usage on future projects
poikilotherm 60da48d
Make config read from os environment variables and provide defaults i…
poikilotherm 9dbae8f
Use a more sophisticated env var concatenating to autobuild the Datav…
poikilotherm 17a199e
Refactor get_api_token.py to be K8s and docker friendly.
poikilotherm f0f9cc5
Adding docs about get_api_token.py
poikilotherm 4ccd3d5
Add Jenkinsfile for container image building and pushing to DockerHub
poikilotherm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM python:3-alpine | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY requirements.txt ./ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY data data/ | ||
COPY *.py *.py.sample ./ | ||
RUN mv dvconfig.py.sample dvconfig.py | ||
|
||
CMD [ "python", "./create_sample_data.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
void setBuildStatus(String message, String state) { | ||
step([ | ||
$class: "GitHubCommitStatusSetter", | ||
reposSource: [$class: "ManuallyEnteredRepositorySource", url: "${env.GIT_URL}"], | ||
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "ci/docker/dataverse-sample-data"], | ||
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]], | ||
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ] | ||
]); | ||
} | ||
|
||
pipeline { | ||
agent any | ||
environment { | ||
DOCKER_IMAGE_NAME = "iqss/dataverse-sample-data" | ||
DOCKER_IMAGE_TAG = "build-${env.BRANCH_NAME}" | ||
DOCKER_WORKDIR = "." | ||
DOCKER_HUB_CRED = "dockerhub-dataversebot" | ||
DOCKER_REGISTRY = "https://registry.hub.docker.com" | ||
} | ||
stages { | ||
stage('build') { | ||
when { | ||
anyOf { | ||
branch 'master' | ||
branch 'PR-14' | ||
} | ||
} | ||
steps { | ||
script { | ||
docker_image = docker.build("${env.DOCKER_IMAGE_NAME}:${env.DOCKER_IMAGE_TAG}", "--pull ${env.DOCKER_WORKDIR}") | ||
} | ||
} | ||
} | ||
stage('push') { | ||
when { | ||
anyOf { | ||
branch 'master' | ||
branch 'PR-14' | ||
} | ||
} | ||
steps { | ||
script { | ||
// Push master image to latest tag | ||
docker.withRegistry("${env.DOCKER_REGISTRY}", "${env.DOCKER_HUB_CRED}") { | ||
docker_image.push("latest") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
post { | ||
success { | ||
setBuildStatus("Image build and push succeeded", "SUCCESS"); | ||
} | ||
failure { | ||
setBuildStatus("Image build or push failed", "FAILURE"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,35 @@ | ||
base_url = 'http://localhost:8080' | ||
api_token = '' | ||
import os | ||
|
||
# Create the base_url from different parts (very usefull on K8s) or just | ||
# read completely from a single env var. Default to "http://localhost:8080" | ||
host = os.getenv('DATAVERSE_SERVICE_HOST', 'localhost') | ||
port = os.getenv('DATAVERSE_SERVICE_PORT_HTTP', '8080') | ||
proto = os.getenv('DATAVERSE_SERVICE_PORT_PROTO', 'http') | ||
subpath = os.getenv('DATAVERSE_SERVICE_SUBPATH', '') | ||
base_url = os.getenv('BASE_URL', proto+'://'+host+':'+port+subpath) | ||
|
||
api_token = os.getenv('API_TOKEN', '') | ||
|
||
# sample data will be created in the following order | ||
sample_data = [ | ||
'data/dataverses/open-source-at-harvard/open-source-at-harvard.json', | ||
'data/dataverses/open-source-at-harvard/dataverses/dataverse-project/dataverse-project.json', | ||
'data/dataverses/open-source-at-harvard/dataverses/dataverse-project/datasets/dataverse-irc-metrics/dataverse-irc-metrics.json', | ||
'data/dataverses/ecastro/ecastro.json', | ||
'data/dataverses/ecastro/datasets/this-is-my-test-dataset/this-is-my-test-dataset.json', | ||
'data/dataverses/manchester/manchester.json', | ||
'data/dataverses/manchester/datasets/test-dataset/test-dataset.json', | ||
'data/dataverses/HCPDS/HCPDS.json', | ||
'data/dataverses/HCPDS/datasets/reproductive-health-laws-around-the-world/reproductive-health-laws-around-the-world.json', | ||
'data/dataverses/cms/cms.json', | ||
'data/dataverses/cms/datasets/cmssampledata/cmssampledata.json', | ||
'data/dataverses/scholcommlab/scholcommlab.json', | ||
'data/dataverses/scholcommlab/datasets/diabeticconnect/diabeticconnect.json', | ||
'data/dataverses/ubiquity-press/ubiquity-press.json', | ||
'data/dataverses/ubiquity-press/dataverses/jopd/jopd.json', | ||
'data/dataverses/ubiquity-press/dataverses/jopd/datasets/flynn-effect-in-estonia/flynn-effect-in-estonia.json', | ||
'data/dataverses/ubiquity-press/dataverses/jopd/datasets/bafacalo/bafacalo.json', | ||
'data/dataverses/open-source-at-harvard/datasets/open-source-at-harvard/open-source-at-harvard.json', | ||
'data/dataverses/king/king.json', | ||
'data/dataverses/king/datasets/cause-of-death/cause-of-death.json', | ||
'data/dataverses/open-source-at-harvard/open-source-at-harvard.json', | ||
'data/dataverses/open-source-at-harvard/dataverses/dataverse-project/dataverse-project.json', | ||
'data/dataverses/open-source-at-harvard/dataverses/dataverse-project/datasets/dataverse-irc-metrics/dataverse-irc-metrics.json', | ||
'data/dataverses/ecastro/ecastro.json', | ||
'data/dataverses/ecastro/datasets/this-is-my-test-dataset/this-is-my-test-dataset.json', | ||
'data/dataverses/manchester/manchester.json', | ||
'data/dataverses/manchester/datasets/test-dataset/test-dataset.json', | ||
'data/dataverses/HCPDS/HCPDS.json', | ||
'data/dataverses/HCPDS/datasets/reproductive-health-laws-around-the-world/reproductive-health-laws-around-the-world.json', | ||
'data/dataverses/cms/cms.json', | ||
'data/dataverses/cms/datasets/cmssampledata/cmssampledata.json', | ||
'data/dataverses/scholcommlab/scholcommlab.json', | ||
'data/dataverses/scholcommlab/datasets/diabeticconnect/diabeticconnect.json', | ||
'data/dataverses/ubiquity-press/ubiquity-press.json', | ||
'data/dataverses/ubiquity-press/dataverses/jopd/jopd.json', | ||
'data/dataverses/ubiquity-press/dataverses/jopd/datasets/flynn-effect-in-estonia/flynn-effect-in-estonia.json', | ||
'data/dataverses/ubiquity-press/dataverses/jopd/datasets/bafacalo/bafacalo.json', | ||
'data/dataverses/open-source-at-harvard/datasets/open-source-at-harvard/open-source-at-harvard.json', | ||
'data/dataverses/king/king.json', | ||
'data/dataverses/king/datasets/cause-of-death/cause-of-death.json', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,33 @@ | ||
from pyDataverse.api import Api | ||
import json | ||
import dvconfig | ||
from pathlib import Path | ||
import os | ||
import sys | ||
|
||
base_url = dvconfig.base_url | ||
api_token = dvconfig.api_token | ||
api = Api(base_url, api_token) | ||
username = 'dataverseAdmin' | ||
password = 'admin1' | ||
api = Api(base_url, '') | ||
|
||
username = os.getenv('DATAVERSE_USER', 'dataverseAdmin') | ||
password = os.getenv('DATAVERSE_PASSWORD', 'admin1') | ||
# On K8s or with Docker we should get secrets from files, not env vars | ||
if Path(password).is_file(): | ||
f = open(Path(password), 'r') | ||
password = f.read().strip() | ||
f.close() | ||
|
||
endpoint = '/builtin-users/' + username + '/api-token' | ||
params = {} | ||
params['password'] = password | ||
resp = api.get_request(endpoint, params=params, auth=True) | ||
api_token = resp.json()['data']['message'] | ||
print(api_token) | ||
|
||
resp = api.get_request(endpoint, params=params, auth=False) | ||
if resp.json()['status'] == "OK": | ||
api_token = resp.json()['data']['message'] | ||
print(api_token) | ||
sys.exit(0) | ||
else: | ||
print("ERROR receiving API token:", file=sys.stderr) | ||
print(resp.json(), file=sys.stderr) | ||
print("Did you enable :AllowApiTokenLookupViaApi configuration option?", file=sys.stderr) | ||
print("See http://guides.dataverse.org/en/latest/installation/config.html#allowapitokenlookupviaapi", file=sys.stderr) | ||
sys.exit(1) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned that the change to
api_token
will break this:https://github.com/IQSS/dataverse-ansible/blob/1449311f2bb5a260b08c001ab51f85c762b5a510/tasks/sampledata.yml#L52-L56
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it will! But Ansible allows for a regex, so maybe we can change that one?