From 6c9388a58a89c6771a55cad6d335fa8b18a5335a Mon Sep 17 00:00:00 2001 From: Niclas Thobaben Date: Tue, 8 Feb 2022 10:41:30 +0100 Subject: [PATCH] initial commit --- .gitignore | 1 + Dockerfile | 41 ++++++++++++++++++++++++++ Jenkinsfile | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 11 +++++++ 4 files changed, 138 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5032f0d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.tmp \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..46cb240 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM alpine:3.15.0 AS builder + +ARG THTTPD_VERSION=2.29 + +# Install all dependencies required for compiling thttpd +RUN apk add gcc musl-dev make + +# Download thttpd sources +RUN wget http://www.acme.com/software/thttpd/thttpd-${THTTPD_VERSION}.tar.gz \ + && tar xzf thttpd-${THTTPD_VERSION}.tar.gz \ + && mv /thttpd-${THTTPD_VERSION} /thttpd + +# Compile thttpd to a static binary which we can copy around +RUN cd /thttpd \ + && ./configure \ + && make CCOPT='-O2 -s -static' thttpd + +# Create a non-root user to own the files and run our server +RUN adduser -D static + +# Switch to the scratch image +FROM scratch + +EXPOSE 80 + +# Copy over the user +COPY --from=builder /etc/passwd /etc/passwd + +# Copy the thttpd static binary +COPY --from=builder /thttpd/thttpd / + +# Use our non-root user +USER static +WORKDIR /home/static + +# Copy the static website +# Use the .dockerignore file to control what ends up inside the image! +COPY . . + +# Run thttpd +CMD ["/thttpd", "-D", "-h", "0.0.0.0", "-p", "80", "-d", "/home/static", "-u", "static", "-l", "-", "-M", "60"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..2cfd39c --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,85 @@ +pipeline { + agent { label 'docker' } + + environment { + DOCKER_REGISTRY = "docker.nclazz.de" + DOCKER_IMAGE_NAME = "nclazz/static-webserver:latest" + } + + stages { + stage('Build Docker Image') { + steps { + script { + docker.withRegistry("https://$DOCKER_REGISTRY", "jenkins_nexus") { + sh 'docker build --tag $DOCKER_IMAGE_NAME' + sh 'docker push $DOCKER_REGISTRY/$DOCKER_IMAGE_NAME' + sh 'docker rmi $(docker images --filter "dangling=true" -q --no-trunc)' + } + } + } + } + } + post { + always { + cleanWs() + } + failure { + slackSend( + channel: "notifications", + color: "danger", + message: "There is a *build failure* in ${env.JOB_NAME}.\nBuild: ${env.BUILD_URL} " + ) + emailext( + recipientProviders: [developers()], + from: "jenkins@nclazz.de", + subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} failed", + body: """ + There is a build failure in ${env.JOB_NAME}. + Build: ${env.BUILD_URL} + Logs: ${env.BUILD_URL}console + Changes: ${env.BUILD_URL}changes + -- + """ + ) + } + unstable { + slackSend( + channel: "notifications", + color: "warning", + message: "Some tests have failed in ${env.JOB_NAME}.\nBuild: ${env.BUILD_URL} " + ) + emailext( + recipientProviders: [developers()], + from: "jenkins@nclazz.de", + subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} unstable", + body: """ + Some tests have failed in ${env.JOB_NAME}. + Build: ${env.BUILD_URL} + Logs: ${env.BUILD_URL}console + Changes: ${env.BUILD_URL}changes + -- + """ + ) + } + fixed { + slackSend( + channel: "notifications", + color: "good", + message: "The build ${env.JOB_NAME} completed successfully and is back to normal.\nBuild: ${env.BUILD_URL} " + ) + emailext( + recipientProviders: [developers()], + from: "jenkins@nclazz.de", + subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} fixed", + body: """ + The build ${env.JOB_NAME} completed successfully and is back to normal. + + Build: ${env.BUILD_URL} + Logs: ${env.BUILD_URL}console + Changes: ${env.BUILD_URL}changes + -- + """ + ) + } + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a2fb294 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +Static Webserver +================================ + +Static Webserver is a simple docker (base) image for serving static content. +Its based on [this](https://lipanski.com/posts/smallest-docker-image-static-website) blog article by Florin Lipan. + +The resultung image is only `186 KB` + size of the static content. + +Usage +-------------------------------- +Use this image as base image and copy all static content to `/home/static/`. \ No newline at end of file