-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from Amsterdam/release/2.0.0
Release/2.0.0
- Loading branch information
Showing
59 changed files
with
1,323 additions
and
771 deletions.
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,52 @@ | ||
FROM amsterdam/python:3.8-buster as app | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
ENV CONSUL_HOST=${CONSUL_HOST:-notset} | ||
ENV CONSUL_PORT=${CONSUL_PORT:-8500} | ||
ENV DATAPUNT_API_URL=${DATAPUNT_API_URL:-https://api.data.amsterdam.nl/} | ||
|
||
ARG https_proxy=http://10.240.2.1:8080/ | ||
ENV https_proxy=$https_proxy | ||
|
||
WORKDIR /app_install | ||
ADD requirements.txt requirements.txt | ||
RUN pip install -r requirements.txt | ||
|
||
ADD deploy /deploy | ||
|
||
WORKDIR /src | ||
ADD src . | ||
|
||
ARG SECRET_KEY=collectstatic | ||
RUN python manage.py collectstatic --no-input | ||
|
||
USER datapunt | ||
|
||
CMD ["/deploy/docker-run.sh"] | ||
|
||
# devserver | ||
FROM app as dev | ||
|
||
USER root | ||
WORKDIR /app_install | ||
ADD requirements_dev.txt requirements_dev.txt | ||
RUN pip install -r requirements_dev.txt | ||
RUN chmod -R a+r /app_install | ||
|
||
WORKDIR /src | ||
USER datapunt | ||
|
||
# Any process that requires to write in the home dir | ||
# we write to /tmp since we have no home dir | ||
ENV HOME /tmp | ||
|
||
CMD ["python manage.py runserver 0.0.0.0"] | ||
|
||
# tests | ||
FROM dev as tests | ||
|
||
USER datapunt | ||
|
||
ENV COVERAGE_FILE=/tmp/.coverage | ||
|
||
CMD ["pytest"] |
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,104 +1,110 @@ | ||
#!groovy | ||
def PROJECT_NAME = "stadsarchief" | ||
def SLACK_CHANNEL = '#opdrachten-deployments' | ||
def PLAYBOOK = 'deploy-stadsarchief.yml' | ||
def SLACK_MESSAGE = [ | ||
"title_link": BUILD_URL, | ||
"fields": [ | ||
["title": "Project","value": PROJECT_NAME], | ||
["title":"Branch", "value": BRANCH_NAME, "short":true], | ||
["title":"Build number", "value": BUILD_NUMBER, "short":true] | ||
] | ||
] | ||
|
||
def tryStep(String message, Closure block, Closure tearDown = null) { | ||
try { | ||
block() | ||
} | ||
catch (Throwable t) { | ||
slackSend message: "${env.JOB_NAME}: ${message} failure ${env.BUILD_URL}", channel: '#ci-channel', color: 'danger' | ||
|
||
throw t | ||
} | ||
finally { | ||
if (tearDown) { | ||
tearDown() | ||
} | ||
} | ||
} | ||
|
||
pipeline { | ||
agent any | ||
|
||
node { | ||
stage("Checkout") { | ||
checkout scm | ||
environment { | ||
SHORT_UUID = sh( script: "head /dev/urandom | tr -dc A-Za-z0-9 | head -c10", returnStdout: true).trim() | ||
COMPOSE_PROJECT_NAME = "${PROJECT_NAME}-${env.SHORT_UUID}" | ||
VERSION = env.BRANCH_NAME.replace('/', '-').toLowerCase().replace( | ||
'master', 'latest' | ||
) | ||
IS_RELEASE = "${env.BRANCH_NAME ==~ "release/.*"}" | ||
} | ||
|
||
stage('Test') { | ||
tryStep "test", { | ||
withCredentials([[$class: 'StringBinding', credentialsId: 'BOUWDOSSIERS_OBJECTSTORE_PASSWORD', variable: 'BOUWDOSSIERS_OBJECTSTORE_PASSWORD']]) { | ||
sh "docker-compose -p stadsarchief -f src/.jenkins/test/docker-compose.yml build && " + | ||
"docker-compose -p stadsarchief -f src/.jenkins/test/docker-compose.yml run -u root --rm tests" | ||
} | ||
}, { | ||
sh "docker-compose -p stadsarchief -f src/.jenkins/test/docker-compose.yml down" | ||
stages { | ||
stage('Test') { | ||
steps { | ||
sh 'make test' | ||
} | ||
} | ||
} | ||
|
||
stage("Build image") { | ||
tryStep "build", { | ||
docker.withRegistry('https://repo.data.amsterdam.nl','docker-registry') { | ||
def image = docker.build("datapunt/stadsarchief:${env.BUILD_NUMBER}", "src") | ||
image.push() | ||
stage('Build') { | ||
steps { | ||
sh 'make build' | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
String BRANCH = "${env.BRANCH_NAME}" | ||
|
||
if (BRANCH == "master") { | ||
|
||
node { | ||
stage('Push acceptance image') { | ||
tryStep "image tagging", { | ||
docker.withRegistry('https://repo.data.amsterdam.nl','docker-registry') { | ||
def image = docker.image("datapunt/stadsarchief:${env.BUILD_NUMBER}") | ||
image.pull() | ||
image.push("acceptance") | ||
stage('Push and deploy') { | ||
when { | ||
anyOf { | ||
branch 'master' | ||
buildingTag() | ||
environment name: 'IS_RELEASE', value: 'true' | ||
} | ||
} | ||
} | ||
} | ||
stages { | ||
stage('Push') { | ||
steps { | ||
retry(3) { | ||
sh 'make push_semver' | ||
} | ||
} | ||
} | ||
|
||
node { | ||
stage("Deploy to ACC") { | ||
tryStep "deployment", { | ||
build job: 'Subtask_Openstack_Playbook', | ||
parameters: [ | ||
[$class: 'StringParameterValue', name: 'INVENTORY', value: 'acceptance'], | ||
[$class: 'StringParameterValue', name: 'PLAYBOOK', value: 'deploy-stadsarchief.yml'], | ||
] | ||
} | ||
} | ||
} | ||
stage('Deploy to acceptance') { | ||
when { environment name: 'IS_RELEASE', value: 'true' } | ||
steps { | ||
build job: 'Subtask_Openstack_Playbook', parameters: [ | ||
string(name: 'PLAYBOOK', value: PLAYBOOK), | ||
string(name: 'INVENTORY', value: "acceptance"), | ||
string( | ||
name: 'PLAYBOOKPARAMS', | ||
value: "-e deployversion=${VERSION}" | ||
) | ||
], wait: true | ||
} | ||
} | ||
|
||
stage('Waiting for approval') { | ||
slackSend channel: '#ci-channel', color: 'warning', message: 'Stadsarchief is waiting for Production Release - please confirm' | ||
input "Deploy to Production?" | ||
} | ||
stage('Deploy to production') { | ||
when { buildingTag() } | ||
steps { | ||
build job: 'Subtask_Openstack_Playbook', parameters: [ | ||
string(name: 'PLAYBOOK', value: PLAYBOOK), | ||
string(name: 'INVENTORY', value: "production"), | ||
string( | ||
name: 'PLAYBOOKPARAMS', | ||
value: "-e deployversion=${VERSION}" | ||
) | ||
], wait: true | ||
|
||
node { | ||
stage('Push production image') { | ||
tryStep "image tagging", { | ||
docker.withRegistry('https://repo.data.amsterdam.nl','docker-registry') { | ||
def image = docker.image("datapunt/stadsarchief:${env.BUILD_NUMBER}") | ||
image.pull() | ||
image.push("production") | ||
image.push("latest") | ||
slackSend(channel: SLACK_CHANNEL, attachments: [SLACK_MESSAGE << | ||
[ | ||
"color": "#36a64f", | ||
"title": "Deploy to production succeeded :rocket:", | ||
] | ||
]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
node { | ||
stage("Deploy") { | ||
tryStep "deployment", { | ||
build job: 'Subtask_Openstack_Playbook', | ||
parameters: [ | ||
[$class: 'StringParameterValue', name: 'INVENTORY', value: 'production'], | ||
[$class: 'StringParameterValue', name: 'PLAYBOOK', value: 'deploy-stadsarchief.yml'], | ||
} | ||
post { | ||
always { | ||
sh 'make clean' | ||
} | ||
failure { | ||
slackSend(channel: SLACK_CHANNEL, attachments: [SLACK_MESSAGE << | ||
[ | ||
"color": "#D53030", | ||
"title": "Build failed :fire:", | ||
] | ||
} | ||
]) | ||
} | ||
} | ||
} | ||
|
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,63 @@ | ||
# This Makefile is based on the Makefile defined in the Python Best Practices repository: | ||
# https://git.datapunt.amsterdam.nl/Datapunt/python-best-practices/blob/master/dependency_management/ | ||
# | ||
# VERSION = 2020.01.29 | ||
.PHONY = help pip-tools install requirements update test init | ||
dc = docker-compose | ||
|
||
help: ## Show this help. | ||
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' | ||
|
||
pip-tools: | ||
pip install pip-tools | ||
|
||
install: pip-tools ## Install requirements and sync venv with expected state as defined in requirements.txt | ||
pip-sync requirements_dev.txt | ||
|
||
requirements: pip-tools ## Upgrade requirements (in requirements.in) to latest versions and compile requirements.txt | ||
pip-compile --upgrade --output-file requirements.txt requirements.in | ||
pip-compile --upgrade --output-file requirements_dev.txt requirements_dev.in | ||
|
||
upgrade: requirements install ## Run 'requirements' and 'install' targets | ||
|
||
migrations: ## Make migrations | ||
$(dc) run --rm app python manage.py makemigrations | ||
|
||
migrate: ## Migrate | ||
$(dc) run --rm app python manage.py migrate | ||
|
||
build: ## Build docker image | ||
$(dc) build | ||
|
||
push: build ## Push docker image to registry | ||
$(dc) push | ||
|
||
push_semver: | ||
VERSION=$${VERSION} $(MAKE) push | ||
VERSION=$${VERSION%\.*} $(MAKE) push | ||
VERSION=$${VERSION%%\.*} $(MAKE) push | ||
|
||
app: ## Run app | ||
$(dc) run --service-ports app | ||
|
||
bash: ## Run the container and start bash | ||
$(dc) run --rm app bash | ||
|
||
test: ## Execute tests | ||
$(dc) run --rm test pytest $(ARGS) | ||
$(dc) run --rm test flake8 --config=./flake8.cfg | ||
|
||
clean: ## Clean docker stuff | ||
$(dc) down -v | ||
|
||
env: ## Print current env | ||
env | sort | ||
|
||
import_bag: ## Populate database with Bag data | ||
${dc} exec database update-table.sh bag bag_verblijfsobject public stadsarchief | ||
${dc} exec database update-table.sh bag bag_ligplaats public stadsarchief | ||
${dc} exec database update-table.sh bag bag_standplaats public stadsarchief | ||
${dc} exec database update-table.sh bag bag_nummeraanduiding public stadsarchief | ||
${dc} exec database update-table.sh bag bag_pand public stadsarchief | ||
${dc} exec database update-table.sh bag bag_verblijfsobjectpandrelatie public stadsarchief | ||
${dc} exec database update-table.sh bag bag_openbareruimte public stadsarchief |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -u # crash on missing env variables | ||
set -e # stop on any error | ||
set -x # print what we are doing | ||
|
||
python manage.py migrate --noinput |
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
Oops, something went wrong.