docker bits

This commit is contained in:
Kameron Kenny 2024-07-01 10:00:52 -04:00
parent 8c8c649693
commit 8e52cede23
No known key found for this signature in database
GPG Key ID: E5006629839D2276
5 changed files with 176 additions and 0 deletions

37
Dockerfile Normal file
View File

@ -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

58
Jenkinsfile vendored Normal file
View File

@ -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'
//}
}
}
}
}
}

48
app/conf/nginx/nginx.conf Normal file
View File

@ -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;
}
}
}

13
docker-compose.yml Normal file
View File

@ -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]

20
entrypoint.sh Executable file
View File

@ -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