From 61e21e10162c1f2d745141ff4b909504fb7bd000 Mon Sep 17 00:00:00 2001 From: amorozov Date: Sat, 2 Sep 2023 00:08:48 +0300 Subject: [PATCH] initial commit --- Dockerfile | 15 +++++++++++++++ Jenkinsfile | 45 ++++++++++++++++++++++++++++++++++++++++++++ docker-entrypoint.sh | 13 +++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1ad706d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +ARG BASE_IMAGE="nginx" + +FROM ${BASE_IMAGE} + +# Install groovy +ENV GROOVY_HOME=/opt/groovy +ENV GROOVY_VERSION=4.0.9 + +# Install ping and ip +RUN apt update && \ + apt install iproute2 && \ + apt install iputils-ping + +ENTRYPOINT [ "docker-entrypoint.sh" ] +CMD [ "app" ] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..f110490 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,45 @@ +def resolveImageTag(env) { + return env.TAG_NAME?.replace(env.RELEASE_TAG_PREFIX, '') ?: 'latest' +} + +def resolveImageName(env) { + return "${env.REGISTRY_HOST}/docker-base-images/${env.IMAGE_BASE_NAME}:${resolveImageTag(env)}" +} + +pipeline { + agent { + docker { + image 'git.tswf.io/docker-base-images/alpine-base:1.0.0-3.17.3' + // Mount docker socket for docker-in-docker + args '-v /var/run/docker.sock:/var/run/docker.sock' + } + } + stages { + stage('prepare') { + steps { + script { + env.IMAGE_BASE_NAME = "jdk14-alpine" + env.RELEASE_TAG_PREFIX = "release-" + env.REGISTRY_HOST = "git.tswf.io" + if (env.TAG_NAME == null) { + env.TAG_NAME = sh(returnStdout: true, script: "git tag --points-at HEAD").trim() + } + } + } + } + stage('build_docker') { + steps { + sh "docker build . --tag ${resolveImageName(env)}" + } + } + stage('push_docker') { + when { + tag "${env.RELEASE_TAG_PREFIX}*" + } + steps { + sh "docker login ${env.REGISTRY_HOST} -u ${env.GITEA_USER} -p ${env.GITEA_OAUTH_TOKEN}" + sh "docker image push ${resolveImageName(env)}" + } + } + } +} \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..025c255 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -Eeo pipefail + +if [ -f "/invoke_initial_script.sh" ]; then + chmod +x /invoke_initial_script.sh + source /invoke_initial_script.sh +fi + +if [[ "$1" = 'app' ]]; then + exec nginx -g 'daemon off;' +else + exec "$@" +fi