diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7e2df15 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +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 photos.kameronkenny.com." + +ARG LOCATION_JEKYLL="/usr/local/jekyll" + +ENV GEM_HOME="/usr/local/gems" +ENV PATH="/usr/local/gems/bin:$PATH" +ENV SITE="photos.kameronkenny.com" +ENV NGINX_CONF_D="$LOCATION_JEKYLL/nginx" + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt update && apt -y upgrade +RUN apt install -y libmagick++-dev + +### Shouldn't need this, it's in the Gemfile, but hold just in case. +#RUN gem install rmagick exifr + +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..213295c --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,58 @@ +pipeline { + agent { + node { + label 'pi501.in.thelinuxpro.net' + } + } + + stages { + stage("verify tooling") { + steps { + sh ''' + docker version + docker info + docker compose version + ''' + } + } + + stage('Build container') { + steps { + script { + def dockerfile = 'Dockerfile' + def containerImage = docker.build("tlp/photos_kameronkenny_com_web:${env.BUILD_ID}", "-f ${dockerfile} .") + + docker.withRegistry('http://docker-registry1.in.thelinuxpro.net:5000') { + containerImage.push() + containerImage.push('latest') + } + } + } + } + + stage('Create contexts') { + steps { + sh 'docker context ls | grep pi502 || docker context create pi502 --docker "host=ssh://pi502.in.thelinuxpro.net"' + } + } + + stage('Start container') { + steps { + script { + //#def status_s = sh(returnStatus: true, script: 'grep $(docker --context pi502 compose ps | tail -n1 | awk \'{ print $2 }\') docker-compose.yml') + sh 'docker --context pi502 compose pull photos_kameronkenny_com_web' + + //if (status_s != 0) { + // sh 'docker --context pi502 compose up -d' + // sh 'docker --context pi502 compose ps' + //} else { + sh 'docker --context pi502 compose down || echo "Container already down or does not exist yet."' + sh 'docker --context pi502 compose up -d' + sh 'docker --context pi502 compose ps' + //} + } + } + + } + } +} diff --git a/app/conf/nginx/nginx.conf b/app/conf/nginx/nginx.conf new file mode 100644 index 0000000..5573ed2 --- /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 4002 default_server; + # listen [::]:80 default_server; + + root /usr/local/jekyll/sites/kameronkenny.com/_site; + + index index.html index.htm; + + 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..56b50d7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +--- + +services: + photos_kameronkenny_com_web: + container_name: photos.kameronkenny.com_web + image: docker-registry1.in.thelinuxpro.net:5000/sites/kameronkenny.com:latest + ports: + - '4002:4002' + 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