From a41fba0c6d2e7b6e1826026f55e0f82422cf1cb9 Mon Sep 17 00:00:00 2001 From: Kameron Kenny <1267885+kkenny@users.noreply.github.com> Date: Sat, 25 May 2024 13:27:21 -0400 Subject: [PATCH] docker / jenkins / nginx stuff --- CNAME | 1 - Dockerfile | 32 ++++++++++++++++++++++++++ Jenkinsfile | 47 ++++++++++++++++++++++++++++++++++++++ app/conf/nginx/nginx.conf | 48 +++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 13 +++++++++++ entrypoint.sh | 20 ++++++++++++++++ 6 files changed, 160 insertions(+), 1 deletion(-) delete mode 100644 CNAME create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100644 app/conf/nginx/nginx.conf create mode 100644 docker-compose.yml create mode 100755 entrypoint.sh diff --git a/CNAME b/CNAME deleted file mode 100644 index 5e9f476..0000000 --- a/CNAME +++ /dev/null @@ -1 +0,0 @@ -thelinux.pro \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ce8209b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM docker-registry1.in.thelinuxpro.net:5000/tlp/tlp_jekyll:0.0.1 + +LABEL version="0.0.1" +LABEL image.author.name="Kameron Kenny" +LABEL image.author.email="kameron@localhost" +LABEL description="A Jekyll site for thelinux.pro." + +ARG LOCATION_JEKYLL="/usr/local/jekyll" + +ENV GEM_HOME="/usr/local/gems" +ENV PATH="/usr/local/gems/bin:$PATH" +ENV SITE="thelinux.pro" +ENV NGINX_CONF_D="$LOCATION_JEKYLL/nginx" + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt update && apt -y upgrade +RUN mkdir -p $LOCATION_JEKYLL/sites/$SITE + +WORKDIR /usr/local/sbin +COPY ./entrypoint.sh . + +WORKDIR $NGINX_CONF_D +COPY ./app/conf/nginx/nginx.conf . + +WORKDIR $LOCATION_JEKYLL/sites/$SITE +COPY . . + +RUN bundle install +RUN JEKYLL_ENV=production bundle exec jekyll build + +ENTRYPOINT /usr/local/sbin/entrypoint.sh diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..28b50d5 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,47 @@ +pipeline { + agent { + label 'pi501.in.thelinuxpro.net' + } + + stages { + stage("verify tooling") { + steps { + sh ''' + docker version + docker info + docker compose version + ''' + } + } + + stage("Build Containers and push to registry") { + steps { + script { + sh 'docker build -t docker-registry1.in.thelinuxpro.net:5000/sites/kameronkenny.com:0.0.3 . --push' + } + } + } + + stage("Tag image as latest") { + steps { + script { + sh 'docker tag docker-registry1.in.thelinuxpro.net:5000/sites/kameronkenny.com:0.0.3 docker-registry1.in.thelinuxpro.net:5000/sites/kameronkenny.com:latest' + } + } + } + + stage("push latest tag") { + steps { + script { + sh 'docker image push docker-registry1.in.thelinuxpro.net:5000/sites/kameronkenny.com:latest' + } + } + } + stage("Start web1 container") { + steps { + sh 'docker compose up -d --no-color' + } + } + } +} + diff --git a/app/conf/nginx/nginx.conf b/app/conf/nginx/nginx.conf new file mode 100644 index 0000000..b1c0f30 --- /dev/null +++ b/app/conf/nginx/nginx.conf @@ -0,0 +1,48 @@ +user www-data; +worker_processes auto; +pid /run/nginx.pid; +error_log /var/log/nginx/error.log; +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + + ## + # Basic Settings + ## + + sendfile on; + tcp_nopush on; + types_hash_max_size 2048; + # server_tokens off; + + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + access_log /var/log/nginx/access.log; + gzip off; + + server { + listen 4000 default_server; + # listen [::]:80 default_server; + + root /usr/local/jekyll/sites/kameronkenny.com/_site; + + index index.html index.htm index.nginx-debian.html; + + server_name _; + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + } + } + +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6883dc5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +--- + +services: + kameronkenny_com_web1: + container_name: kameronkenny.com_web1 + image: docker-registry1.in.thelinuxpro.net:5000/sites/kameronkenny.com:latest + ports: + - '4000:4000' + restart: always + user: root + deploy: + placement: + constraints: [node.role == manager] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..1398951 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +function start_nginx() { + /usr/sbin/nginx -p /usr/local/jekyll/nginx -c nginx.conf +} + +function watchtower() { + while true; do + ps -elf | grep nginx | grep -v grep | grep nginx >/dev/null 2>&1 + RC=$? + + if [[ $RC != 0 ]]; then + start_nginx + fi + + sleep 10 + done +} + +watchtower