diff options
-rw-r--r-- | .scripts.d/10-check.sh | 39 | ||||
-rw-r--r-- | .scripts.d/20-build.sh | 18 | ||||
-rw-r--r-- | .scripts.d/30-test.sh | 30 | ||||
-rw-r--r-- | .scripts.d/40-publish.sh | 30 | ||||
-rw-r--r-- | Jenkinsfile | 21 |
5 files changed, 138 insertions, 0 deletions
diff --git a/.scripts.d/10-check.sh b/.scripts.d/10-check.sh new file mode 100644 index 0000000..e8ddf59 --- /dev/null +++ b/.scripts.d/10-check.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# vim: ai:ts=8:sw=8:noet +set -EeufCo pipefail +export SHELLOPTS # propagate set to children by default +IFS=$'\t\n' + +# check required commands are in place +command -v shellcheck >/dev/null 2>&1 || { + echo 'please install shellcheck' + exit 1 +} +command -v hadolint >/dev/null 2>&1 || { + echo 'please install hadolint' + exit 1 +} +command -v yamllint >/dev/null 2>&1 || { + echo 'please install yamllint' + exit 1 +} + +# check all the Dockerfiles with hadolint +find . \ + -type f \ + -name 'Dockerfile' \ + -print0 | + xargs -0 -r hadolint + +# check all the yaml files with yamllint +find . -type f \ + -regex '.*\.ya?ml\(lint\)?' \ + -print0 | + xargs -0 -r yamllint -s + +# check all sh files with shellcheck +find . \ + -type f \ + -name '*.sh' \ + -print0 | + xargs -0 -r shellcheck diff --git a/.scripts.d/20-build.sh b/.scripts.d/20-build.sh new file mode 100644 index 0000000..56af8df --- /dev/null +++ b/.scripts.d/20-build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# vim: ai:ts=8:sw=8:noet +set -EeufCo pipefail +export SHELLOPTS # propagate set to children by default +IFS=$'\t\n' + +# check required commands are in place +command -v docker >/dev/null 2>&1 || { + echo 'please install docker-client' + exit 1 +} + +docker buildx build \ + --no-cache \ + --pull \ + --load \ + --tag "chn2guevara/languagetool:${BUILD_ID}" \ + . diff --git a/.scripts.d/30-test.sh b/.scripts.d/30-test.sh new file mode 100644 index 0000000..4ec890d --- /dev/null +++ b/.scripts.d/30-test.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# vim: ai:ts=8:sw=8:noet +set -EeufCo pipefail +export SHELLOPTS # propagate set to children by default +IFS=$'\t\n' + +# check required commands are in place +command -v docker >/dev/null 2>&1 || { + echo 'please install docker-client' + exit 1 +} + +# install goss +curl -fsSL https://goss.rocks/install | sh + +export GOSS_SLEEP=${GOSS_SLEEP:-5} +export GOSS_VARS=${GOSS_VARS:-} +export CONTAINER_LOG_OUTPUT=${CONTAINER_LOG_OUTPUT:-} + +# The default 'mount' strategy uses 'sleep infinity' to keep +# the container alive. If there's an ENTRYPOINT or CMD, use 'cp' +# instead to prevent dgoss from overriding it. +if grep -qE '^(ENTRYPOINT|CMD)' Dockerfile; then + export GOSS_FILES_STRATEGY=cp +fi + +goss --gossfile goss.yaml render >goss-full.yaml +mv goss-full.yaml goss.yaml + +dgoss run "chn2guevara/languagetool:${BUILD_ID}" diff --git a/.scripts.d/40-publish.sh b/.scripts.d/40-publish.sh new file mode 100644 index 0000000..3e425c3 --- /dev/null +++ b/.scripts.d/40-publish.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# vim: ai:ts=8:sw=8:noet +set -EeufCo pipefail +export SHELLOPTS # propagate set to children by default +IFS=$'\t\n' + +# check required commands are in place +command -v docker >/dev/null 2>&1 || { + echo 'please install docker-client' + exit 1 +} + +docker login --username "chn2guevara" \ + --password-stdin <<<"$DOCKERHUB_TOKEN" + +docker run --privileged --rm tonistiigi/binfmt --install arm64 +docker buildx create --use --name multi-arch-builder + +DOCKER_TAG="latest" +if [ "$GIT_BRANCH" != "master" ]; then + DOCKER_TAG="${GIT_BRANCH//\//-}" +fi + +docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --no-cache \ + --pull \ + --push \ + --tag "chn2guevara/languagetool:${DOCKER_TAG}" \ + . diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..67faa30 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,21 @@ +pipeline { + agent any + options { ansiColor('xterm') } + stages { + stage('Check') { + agent { + docker { + image 'ghcr.io/super-linter/super-linter:latest' + args '--entrypoint ""' + } + } + steps { sh 'bash .scripts.d/10-check.sh' } + } + stage('Build') { steps { sh 'bash .scripts.d/20-build.sh' } } + stage('Test') { steps { sh 'bash .scripts.d/30-test.sh' } } + stage('Publish') { + environment { DOCKERHUB_TOKEN = credentials('DOCKERHUB_TOKEN') } + steps { sh 'bash .scripts.d/40-publish.sh' } + } + } +} |