Commit 9fed521d authored by Jorge S. Mendes de Jesus's avatar Jorge S. Mendes de Jesus
Browse files

Merge branch 'k8s-prep' into develop

parents 0c180ed0 f58cfdbd
Pipeline #24720 failed with stage
in 26 seconds
......@@ -6,3 +6,4 @@ wsm.rest.sock
logs
.project
.pydevproject
.vscode
\ No newline at end of file
default:
interruptible: false
stages:
- tag
- publish
# tag release
tag:
image: node:12-buster-slim
stage: tag
before_script:
- apt-get update && apt-get install -y --no-install-recommends git-core ca-certificates
- npm install -g semantic-release @semantic-release/changelog @semantic-release/commit-analyzer @semantic-release/gitlab @semantic-release/git @semantic-release/npm @semantic-release/release-notes-generator conventional-changelog conventional-changelog-conventionalcommits
script:
- semantic-release
when: on_success
only:
- master
except:
refs:
- tags
variables:
- $CI_COMMIT_TITLE =~ /^RELEASE:.+$/
# build a new container
build:
stage: publish
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
when: on_success
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$HARBOR_REGISTRY\":{\"username\":\"$HARBOR_USER\",\"password\":\"$HARBOR_PASSWORD\"}}}" > /kaniko/.docker/config.json
- if [ -z $flag ]; then /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $HARBOR_REGISTRY/$HARBOR_PROJECT/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA; else /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $HARBOR_REGISTRY/$HARBOR_PROJECT/$CI_PROJECT_NAME:$CI_COMMIT_TAG --destination $HARBOR_REGISTRY/$HARBOR_PROJECT/$CI_PROJECT_NAME:latest; fi
only:
- tags
- develop
plugins:
- "@semantic-release/gitlab"
branches: ['master']
ci: true
debug: true
dryRun: false
tagFormat: '${version}'
# Global plugin options (will be passed to all plugins)
preset: 'conventionalcommits'
gitlabUrl: 'http://git.wur.nl/' # your gitlab url
# slackWebhook: 'https://slack.xxx.com/hooks/q3dtkec6yjyg9x6616o3atgkkr' # if you need slack notifies
# Responsible for verifying conditions necessary to proceed with the release:
# configuration is correct, authentication token are valid, etc...
verifyConditions:
- '@semantic-release/changelog'
- '@semantic-release/git'
- '@semantic-release/gitlab'
# Responsible for determining the type of the next release (major, minor or patch).
# If multiple plugins with a analyzeCommits step are defined, the release type will be
# the highest one among plugins output.
# Look details at: https://github.com/semantic-release/commit-analyzer#configuration
analyzeCommits:
- path: '@semantic-release/commit-analyzer'
# Responsible for generating the content of the release note.
# If multiple plugins with a generateNotes step are defined,
# the release notes will be the result of the concatenation of each plugin output.
generateNotes:
- path: '@semantic-release/release-notes-generator'
writerOpts:
groupBy: 'type'
commitGroupsSort: 'title'
commitsSort: 'header'
linkCompare: true
linkReferences: true
# Responsible for preparing the release, for example creating or updating files
# such as package.json, CHANGELOG.md, documentation or compiled assets
# and pushing a commit.
prepare:
- path: '@semantic-release/changelog'
- path: '@semantic-release/git'
message: 'RELEASE: ${nextRelease.version}'
assets: ['CHANGELOG.md']
# Responsible for publishing the release.
publish:
- path: '@semantic-release/gitlab'
FROM ubuntu:16.04
MAINTAINER Luís de Sousa <luis.desousa@wur.nl>
FROM ubuntu:18.04
LABEL MAINTAINER Luís de Sousa <luis.desousa@wur.nl>
RUN apt update
RUN apt -y install python-pip python-dev nginx
RUN apt update && apt -y install python-pip python-dev nginx curl && rm -rf /var/lib/apt/lists/*
RUN mkdir -p /var/www/wsm.rest
COPY ./requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt
WORKDIR /var/www/wsm.rest
COPY . .
RUN chmod +x configs/startup.sh
RUN pip install -r requirements.txt
ENTRYPOINT [ "configs/startup.sh" ]
# Expose port 80
EXPOSE 80
STOPSIGNAL SIGQUIT
HEALTHCHECK CMD curl --fail http://localhost:80 || exit 1
CMD ["nginx", "-g", "daemon off;"]
################### Usage #####################
# Build it
# docker build -t ldesousa/wsm.rest .
# Run command
# docker run -dit -v /var/www/wsm.rest:/var/www/wsm.rest -v /data/monoliths:/data/monoliths --name wsm.rest -p 8081:80 ldesousa/wsm.rest
# Set the correct database connection in common/secret.py
# Set the correct database connection in using environment variables or an env-file:
# Attach to the container and run the startup script
# docker attach wsm.rest
# sh /var/www/wsm.rest/configs/startup.sh
# Ctrl+P Ctrl+Q
# Run command with envfile
# docker run -dit --env-file /path/to/envfile -v /data/monoliths:/data/monoliths --name wsm.rest -p 8081:80 ldesousa/wsm.rest
# Declaring variables inline:
# docker run -dit -e DB_HOST=scomp1270.wurnet.nl -e DB_NAME=isric -e DB_USER=haas005 -e DB_PASSWORD=wur -e DB_PORT=5479 -v /data/monoliths:/data/monoliths --name wsm.rest -p 8081:80 ldesousa/wsm.rest
\ No newline at end of file
......@@ -102,23 +102,19 @@ To build the container image change to the project folder and run:
`docker build -t ldesousa/wsm.rest .`
The resulting image is named `ldesousa/wsm.rest`. To run the image it is
necessary to map the source code folder and port 80 (where nginx listens):
The resulting image is named `ldesousa/wsm.rest`.
To run the image it is necessary to map the right environment variables to connect to the database as well as mount the source code folder and bind port 80 (where nginx listens):
`docker run -dit -v /var/www/wsm.rest:/var/www/wsm.rest --name wsm.rest -p 8081:80 ldesousa/wsm.rest`
Gunicorn can only be started after the source code folder has been mapped. To
do so attach to the running container (named `wsm.rest`):
`docker attach wsm.rest`
And then run the startup script:
`sh /var/www/wsm.rest/configs/startup.sh`
Finally, detach orderly from the running container with the escape sequence:
Docker run command with envfile:
```bash
docker run -dit --env-file /path/to/envfile -v /data/monoliths:/data/monoliths --name wsm.rest -p 8081:80 ldesousa/wsm.rest
```
Docker run command with variables inline:
```bash
docker run -dit -e DB_HOST=scomp1270.wurnet.nl -e DB_NAME=isric -e DB_USER=haas005 -e DB_PASSWORD=wur -e DB_PORT=5479 -v /data/monoliths:/data/monoliths --name wsm.rest -p 8081:80 ldesousa/wsm.rest
```
`Ctrl+P Ctrl+Q`
Your container will now be available on [localhost:8081](http://localhost:8081)
OC deployment
=============
......
"""Password of database"""
"""This is just an example, change to the correct values and rename the file to
secret.py"""
DB={"host":"scomp1270.wurnet.nl","database":"isric", "user":"haas005", "password":"1515NewPW","port":"5479"}
"""Secrets will be read from environment variables, and have some example default values set."""
from os import environ
# Get environment variables and set default if none specified:
DB_HOST = environ.get("DB_HOST", "scomp1270.wurnet.nl")
DB_NAME = environ.get("DB_NAME", "isric")
DB_USER = environ.get("DB_USER", "haas005")
DB_PASSWORD = environ.get("DB_PASSWORD", "1515NewPW")
DB_PORT = environ.get("DB_PORT", "5479")
DB={"host":DB_HOST,"database":DB_NAME, "user":DB_USER, "password":DB_PASSWORD,"port":DB_PORT}
......@@ -2,6 +2,7 @@
cd /var/www/wsm.rest
mkdir logs
echo "Launching Gunicorn..."
nohup /usr/local/bin/gunicorn wsgi:app --workers 3 --bind unix:wsm.rest.sock -m 007 </dev/null >logs/gunicorn.log 2>&1 &
......@@ -9,9 +10,6 @@ echo "Setting up nginx config."
rm -f /etc/nginx/sites-enabled/default
cp /var/www/wsm.rest/configs/wsm.rest.nginx /etc/nginx/sites-enabled/wsm.rest
echo "Launching nginx..."
nohup nginx </dev/null >logs/nginx.log 2>&1 &
# Wait a little for Gunicorn to set up
sleep 2
......@@ -19,3 +17,4 @@ echo "Fixing access to socket."
chown www-data:www-data /var/www/wsm.rest/wsm.rest.sock
echo "All done. Good to go!"
exec "$@"
\ No newline at end of file
server {
listen 80;
server_name server_domain_or_IP;
server_name localhost;
access_log /dev/stdout;
error_log /dev/stderr;
location / {
include proxy_params;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment