Skip to content

Commit b51a2a5

Browse files
committedApr 28, 2021
Initial commit of files
1 parent 24fa22b commit b51a2a5

12 files changed

+481
-0
lines changed
 

‎.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
.env
3+
.DS_Store
4+
._*
5+
*.code-workspace
6+
.vscode

‎.jenkins/Jenkinsfile

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
pipeline {
2+
agent {
3+
label 'docker-multiarch'
4+
}
5+
options {
6+
buildDiscarder(logRotator(numToKeepStr: '5'))
7+
disableConcurrentBuilds()
8+
ansiColor('xterm')
9+
}
10+
environment {
11+
IMAGE = 'nginx-full'
12+
BUILDX_NAME = "${IMAGE}_${GIT_BRANCH}"
13+
BRANCH_LOWER = "${BRANCH_NAME.toLowerCase().replaceAll('/', '-')}"
14+
// Software versions; OpenResty does not support Lua >= 5.2
15+
OPENRESTY_VERSION = '1.19.3.1'
16+
LUA_VERSION = '5.1.5'
17+
LUAROCKS_VERSION = '3.3.1'
18+
}
19+
stages {
20+
stage('Environment') {
21+
parallel {
22+
stage('Master') {
23+
when {
24+
branch 'master'
25+
}
26+
steps {
27+
script {
28+
env.BASE_TAG = 'latest'
29+
env.BUILDX_PUSH_TAGS = "-t docker.io/jc21/${IMAGE}:${BASE_TAG}"
30+
env.BUILDX_PUSH_TAGS_NODE = "-t docker.io/jc21/${IMAGE}:node"
31+
env.BUILDX_PUSH_TAGS_GOLANG = "-t docker.io/jc21/${IMAGE}:golang"
32+
}
33+
}
34+
}
35+
stage('Other') {
36+
when {
37+
not {
38+
branch 'master'
39+
}
40+
}
41+
steps {
42+
script {
43+
// Defaults to the Branch name, which is applies to all branches AND pr's
44+
env.BASE_TAG = "github-${BRANCH_LOWER}"
45+
env.BUILDX_PUSH_TAGS = "-t docker.io/jc21/${IMAGE}:${BASE_TAG}"
46+
env.BUILDX_PUSH_TAGS_NODE = "${BUILDX_PUSH_TAGS}-node"
47+
env.BUILDX_PUSH_TAGS_GOLANG = "${BUILDX_PUSH_TAGS}-golang"
48+
}
49+
}
50+
}
51+
}
52+
}
53+
stage('Base Build') {
54+
environment {
55+
BUILDX_NAME = "${IMAGE}_${GIT_BRANCH}_base"
56+
}
57+
steps {
58+
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
59+
sh 'docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"'
60+
sh "./scripts/buildx --push -f docker/Dockerfile ${BUILDX_PUSH_TAGS}"
61+
}
62+
}
63+
}
64+
stage('Other Builds') {
65+
parallel {
66+
stage('Golang') {
67+
environment {
68+
BUILDX_NAME = "${IMAGE}_${GIT_BRANCH}_golang"
69+
}
70+
steps {
71+
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
72+
sh 'docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"'
73+
sh "./scripts/buildx --push -f docker/Dockerfile.golang ${BUILDX_PUSH_TAGS_GOLANG}"
74+
}
75+
}
76+
}
77+
stage('Node') {
78+
environment {
79+
BUILDX_NAME = "${IMAGE}_${GIT_BRANCH}_node"
80+
}
81+
steps {
82+
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
83+
sh 'docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"'
84+
sh "./scripts/buildx --push -f docker/Dockerfile.node ${BUILDX_PUSH_TAGS_NODE}"
85+
}
86+
}
87+
}
88+
}
89+
}
90+
stage('PR Comment') {
91+
when {
92+
allOf {
93+
changeRequest()
94+
not {
95+
equals expected: 'UNSTABLE', actual: currentBuild.result
96+
}
97+
}
98+
}
99+
steps {
100+
script {
101+
def comment = pullRequest.comment("""Docker Image for build ${BUILD_NUMBER} is available on [DockerHub](https://cloud.docker.com/repository/docker/jc21/${IMAGE}) as:
102+
103+
- `jc21/${IMAGE}:github-${BRANCH_LOWER}`
104+
- `jc21/${IMAGE}:github-${BRANCH_LOWER}-node`
105+
- `jc21/${IMAGE}:github-${BRANCH_LOWER}-golang`
106+
""")
107+
}
108+
}
109+
}
110+
}
111+
post {
112+
success {
113+
juxtapose event: 'success'
114+
sh 'figlet "SUCCESS"'
115+
}
116+
failure {
117+
juxtapose event: 'failure'
118+
sh 'figlet "FAILURE"'
119+
}
120+
unstable {
121+
juxtapose event: 'unstable'
122+
sh 'figlet "UNSTABLE"'
123+
}
124+
}
125+
}

‎docker/Dockerfile

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#############
2+
# Go Builder
3+
#############
4+
5+
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang as go
6+
7+
ENV MKCERT_VERSION=1.4.2
8+
RUN mkdir /workspace
9+
WORKDIR /workspace
10+
RUN go get github.com/amacneil/dbmate
11+
RUN wget -O mkcert.tgz "https://github.com/FiloSottile/mkcert/archive/v${MKCERT_VERSION}.tar.gz"
12+
RUN tar -xzf mkcert.tgz
13+
WORKDIR "/workspace/mkcert-${MKCERT_VERSION}"
14+
RUN go build -ldflags "-X main.Version=v${MKCERT_VERSION}" -o /bin/mkcert
15+
16+
#############
17+
# Nginx Builder
18+
#############
19+
20+
FROM --platform=${TARGETPLATFORM:-linux/amd64} debian:stable-slim as builder
21+
22+
ARG OPENRESTY_VERSION
23+
ARG LUA_VERSION
24+
ARG LUAROCKS_VERSION
25+
26+
RUN apt-get update \
27+
&& apt-get install -y wget build-essential libreadline-dev openssl unzip libncurses-dev libpcre3-dev libssl-dev zlib1g-dev
28+
29+
# Lua build
30+
ADD ./scripts/build-lua /tmp/build-lua
31+
RUN /tmp/build-lua
32+
33+
# Nginx build
34+
ADD ./scripts/build-openresty /tmp/build-openresty
35+
RUN /tmp/build-openresty
36+
37+
#############
38+
# Final Image
39+
#############
40+
41+
FROM --platform=${TARGETPLATFORM:-linux/amd64} debian:stable-slim
42+
LABEL maintainer="Jamie Curnow <jc@jc21.com>"
43+
44+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
45+
46+
# Env var for bashrc
47+
ARG OPENRESTY_VERSION
48+
ENV OPENRESTY_VERSION=${OPENRESTY_VERSION}
49+
50+
ARG TARGETPLATFORM
51+
RUN echo "Base: debian:stable-slim, ${TARGETPLATFORM:-linux/amd64}" > /built-for-arch
52+
53+
# OpenResty uses LuaJIT which has a dependency on GCC
54+
RUN apt-get update \
55+
&& apt-get install -y curl figlet openssl libpcre3 zlib1g apache2-utils tzdata perl libreadline7 unzip libncurses6 make gcc \
56+
&& apt-get clean \
57+
&& rm -rf /var/lib/apt/lists/*
58+
59+
ADD ./files/.bashrc /root/.bashrc
60+
61+
# Copy lua and luarocks builds from first image
62+
COPY --from=builder /tmp/lua /tmp/lua
63+
COPY --from=builder /tmp/luarocks /tmp/luarocks
64+
ADD ./scripts/install-lua /tmp/install-lua
65+
66+
# Copy openresty build from first image
67+
COPY --from=builder /tmp/openresty /tmp/openresty
68+
ADD ./scripts/install-openresty /tmp/install-openresty
69+
70+
# Copy golang built packages
71+
COPY --from=go /bin/mkcert /bin/mkcert
72+
COPY --from=go /go/bin/dbmate /bin/dbmate
73+
74+
RUN /tmp/install-lua \
75+
&& /tmp/install-openresty \
76+
&& rm -f /tmp/install-lua \
77+
&& rm -f /tmp/install-openresty \
78+
&& apt-get remove -y make gcc \
79+
&& apt-get autoremove -y
80+
81+
LABEL org.label-schema.schema-version="1.0" \
82+
org.label-schema.license="MIT" \
83+
org.label-schema.name="nginx-full" \
84+
org.label-schema.description="A base image for use by Nginx Proxy Manager" \
85+
org.label-schema.url="https://github.com/jc21/docker-nginx-full" \
86+
org.label-schema.vcs-url="https://github.com/jc21/docker-nginx-full.git" \
87+
org.label-schema.cmd="docker run --rm -ti jc21/nginx-full:latest"

‎docker/Dockerfile.golang

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang as go
2+
FROM --platform=${TARGETPLATFORM:-linux/amd64} jc21/nginx-full:${BASE_TAG:-latest}
3+
4+
ARG TARGETPLATFORM
5+
6+
RUN echo "Golang: jc21/nginx-full:${BASE_TAG:-latest}, ${TARGETPLATFORM:-linux/amd64}" >> /built-for-arch
7+
8+
LABEL maintainer="Jamie Curnow <jc@jc21.com>"
9+
10+
RUN apt-get update \
11+
&& apt-get install -y wget \
12+
&& apt-get clean \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# copy go from golang
16+
COPY --from=go /usr/local/go /usr/local/go
17+
18+
ENV GOPATH=/opt/go PATH="/usr/local/go/bin:$PATH:/opt/go/bin"
19+
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" \
20+
&& chmod -R 777 "$GOPATH" \
21+
&& echo "====> ${TARGETPLATFORM}: $(go version)"
22+
23+
WORKDIR /root
24+
25+
# Gotools
26+
RUN if [ "$TARGETPLATFORM" == "" ] || [ "$TARGETPLATFORM" == "linux/amd64" ]; then cd /usr && wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.39.0; fi
27+
RUN go get -u github.com/kyoh86/richgo \
28+
&& rm -rf /root/.cache/go-build

‎docker/Dockerfile.node

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM --platform=${TARGETPLATFORM:-linux/amd64} jc21/nginx-full:${BASE_TAG:-latest}
2+
LABEL maintainer="Jamie Curnow <jc@jc21.com>"
3+
4+
ARG TARGETPLATFORM
5+
RUN echo "Node: jc21/nginx-full:${BASE_TAG:-latest}, ${TARGETPLATFORM:-linux/amd64}" >> /built-for-arch
6+
7+
ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
8+
9+
RUN curl -fsSL https://deb.nodesource.com/setup_15.x | bash - \
10+
&& apt-get update \
11+
&& apt-get install -y gcc make g++ git nodejs \
12+
&& apt-get clean \
13+
&& rm -rf /var/lib/apt/lists/* \
14+
&& npm install -g yarn
15+
16+
# Check nodejs works on this architecture
17+
COPY ./files/test.js /tmp/test.js
18+
RUN node /tmp/test.js \
19+
&& rm -f /tmp/test.js

‎files/.bashrc

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
if [ -t 1 ]; then
4+
export PS1="\e[1;34m[\e[1;33m\u@\e[1;32mdocker-\h\e[1;37m:\w\[\e[1;34m]\e[1;36m\\$ \e[0m"
5+
fi
6+
7+
# Aliases
8+
alias l='ls -lAsh --color'
9+
alias ls='ls -C1 --color'
10+
alias cp='cp -ip'
11+
alias rm='rm -i'
12+
alias mv='mv -i'
13+
alias h='cd ~;clear;'
14+
15+
echo -e -n '\E[1;34m'
16+
figlet -w 120 "nginx-full"
17+
echo -e "\E[1;36mOpenResty \E[1;32m${OPENRESTY_VERSION:-unknown}\E[1;36m, Kernel \E[1;32m$(uname -r)\E[0m"
18+
echo -e -n '\E[1;34m'
19+
cat /built-for-arch
20+
echo -e -n '\E[0m'
21+
echo

‎files/test.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
fs = require('fs');
2+
3+
tmpfile = '/tmp/nodejstest';
4+
5+
fs.writeFile(tmpfile, 'this is test data', function (err, data) {
6+
if (err) {
7+
console.error(err);
8+
process.exit(1);
9+
return;
10+
}
11+
12+
console.log('Wrote test file successfully');
13+
14+
// Delete file
15+
try {
16+
fs.unlinkSync(tmpfile)
17+
} catch (err) {
18+
console.error(err);
19+
process.exit(1);
20+
return;
21+
}
22+
23+
console.log('Removed test file successfully');
24+
});
25+

‎scripts/build-lua

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash -e
2+
3+
BLUE='\E[1;34m'
4+
CYAN='\E[1;36m'
5+
YELLOW='\E[1;33m'
6+
GREEN='\E[1;32m'
7+
RESET='\E[0m'
8+
9+
echo -e "${BLUE}${CYAN}Building Lua ${YELLOW}${LUA_VERSION}...${RESET}"
10+
11+
cd /tmp
12+
wget "http://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz"
13+
tar -xzf lua-${LUA_VERSION}.tar.gz
14+
mv /tmp/lua-${LUA_VERSION} /tmp/lua
15+
cd /tmp/lua
16+
17+
make linux test
18+
# We have to install Lua for the Luarocks build to succeed, it will be installed again when building the final image
19+
make install
20+
21+
echo -e "${BLUE}${GREEN}Lua build completed${RESET}"
22+
23+
echo -e "${BLUE}${CYAN}Building Luarocks ${YELLOW}${LUAROCKS_VERSION}...${RESET}"
24+
25+
cd /tmp
26+
wget "http://luarocks.github.io/luarocks/releases/luarocks-${LUAROCKS_VERSION}.tar.gz"
27+
tar -xzf luarocks-${LUAROCKS_VERSION}.tar.gz
28+
mv /tmp/luarocks-${LUAROCKS_VERSION} /tmp/luarocks
29+
cd /tmp/luarocks
30+
31+
./configure
32+
make
33+
34+
echo -e "${BLUE}${GREEN}Luarocks build completed${RESET}"

‎scripts/build-openresty

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash -e
2+
3+
BLUE='\E[1;34m'
4+
CYAN='\E[1;36m'
5+
YELLOW='\E[1;33m'
6+
GREEN='\E[1;32m'
7+
RESET='\E[0m'
8+
9+
echo -e "${BLUE}${CYAN}Building OpenResty ${YELLOW}${OPENRESTY_VERSION}...${RESET}"
10+
11+
cd /tmp
12+
wget "https://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz"
13+
tar -xzf openresty-${OPENRESTY_VERSION}.tar.gz
14+
mv /tmp/openresty-${OPENRESTY_VERSION} /tmp/openresty
15+
cd /tmp/openresty
16+
17+
./configure \
18+
--prefix=/etc/nginx \
19+
--sbin-path=/usr/sbin/nginx \
20+
--modules-path=/usr/lib/nginx/modules \
21+
--conf-path=/etc/nginx/nginx.conf \
22+
--error-log-path=/var/log/nginx/error.log \
23+
--http-log-path=/var/log/nginx/access.log \
24+
--pid-path=/var/run/nginx.pid \
25+
--lock-path=/var/run/nginx.lock \
26+
--http-client-body-temp-path=/var/cache/nginx/client_temp \
27+
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
28+
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
29+
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
30+
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
31+
--user=nginx \
32+
--group=nginx \
33+
--with-compat \
34+
--with-threads \
35+
--with-http_addition_module \
36+
--with-http_auth_request_module \
37+
--with-http_dav_module \
38+
--with-http_flv_module \
39+
--with-http_gunzip_module \
40+
--with-http_gzip_static_module \
41+
--with-http_mp4_module \
42+
--with-http_random_index_module \
43+
--with-http_realip_module \
44+
--with-http_secure_link_module \
45+
--with-http_slice_module \
46+
--with-http_ssl_module \
47+
--with-http_stub_status_module \
48+
--with-http_sub_module \
49+
--with-http_v2_module \
50+
--with-mail \
51+
--with-mail_ssl_module \
52+
--with-stream \
53+
--with-stream_realip_module \
54+
--with-stream_ssl_module \
55+
--with-stream_ssl_preread_module
56+
57+
make -j2
58+
59+
echo -e "${BLUE}${GREEN}OpenResty build completed${RESET}"

‎scripts/buildx

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash -e
2+
3+
BLUE='\E[1;34m'
4+
CYAN='\E[1;36m'
5+
YELLOW='\E[1;33m'
6+
GREEN='\E[1;32m'
7+
RESET='\E[0m'
8+
9+
echo -e "${BLUE}${CYAN}Building docker multiarch: ${YELLOW}${*}${RESET}"
10+
11+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
cd "${DIR}/.."
13+
14+
# Buildx Builder
15+
docker buildx create --name "${BUILDX_NAME:-nginx-full}" || echo
16+
docker buildx use "${BUILDX_NAME:-nginx-full}"
17+
18+
docker buildx build \
19+
--platform linux/amd64,linux/arm64,linux/arm/7 \
20+
--progress plain \
21+
--pull \
22+
--build-arg BASE_TAG \
23+
--build-arg OPENRESTY_VERSION \
24+
--build-arg LUA_VERSION \
25+
--build-arg LUAROCKS_VERSION \
26+
$@ \
27+
.
28+
29+
docker buildx rm "${BUILDX_NAME:-nginx-full}"
30+
31+
echo -e "${BLUE}${GREEN}Multiarch build Complete${RESET}"

‎scripts/install-lua

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash -e
2+
3+
BLUE='\E[1;34m'
4+
CYAN='\E[1;36m'
5+
YELLOW='\E[1;33m'
6+
GREEN='\E[1;32m'
7+
RESET='\E[0m'
8+
9+
echo -e "${BLUE}${CYAN}Installing Lua ${YELLOW}${LUA_VERSION}...${RESET}"
10+
11+
cd /tmp/lua
12+
make install
13+
rm -rf /tmp/lua
14+
15+
echo -e "${BLUE}${GREEN}Lua install completed${RESET}"
16+
17+
echo -e "${BLUE}${CYAN}Installing Luarocks ${YELLOW}${LUAROCKS_VERSION}...${RESET}"
18+
19+
cd /tmp/luarocks
20+
make install
21+
rm -rf /tmp/luarocks
22+
23+
echo -e "${BLUE}${GREEN}Luarocks install completed${RESET}"

‎scripts/install-openresty

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash -e
2+
3+
BLUE='\E[1;34m'
4+
CYAN='\E[1;36m'
5+
YELLOW='\E[1;33m'
6+
GREEN='\E[1;32m'
7+
RESET='\E[0m'
8+
9+
echo -e "${BLUE}${CYAN}Installing OpenResty ${YELLOW}${OPENRESTY_VERSION}...${RESET}"
10+
11+
cd /tmp/openresty
12+
make install
13+
rm -rf /tmp/openresty
14+
15+
echo -e "${BLUE}${GREEN}OpenResty install completed${RESET}"
16+
17+
echo -e "${BLUE}${CYAN}Installing OpenResty plugins...${RESET}"
18+
19+
cd /
20+
luarocks install lua-cjson
21+
luarocks install lua-resty-openidc
22+
23+
echo -e "${BLUE}${GREEN}OpenResty plugins install completed${RESET}"

0 commit comments

Comments
 (0)
Please sign in to comment.