autoconf - multi arch Dockerfile
This commit is contained in:
parent
92569679b6
commit
b86ded3d1c
15
autoconf/Dockerfile-amd64
Normal file
15
autoconf/Dockerfile-amd64
Normal file
@ -0,0 +1,15 @@
|
||||
FROM amd64/alpine
|
||||
|
||||
RUN apk add py3-pip apache2-utils bash && \
|
||||
pip3 install docker && \
|
||||
mkdir /opt/entrypoint && \
|
||||
mkdir -p /opt/confs/site
|
||||
|
||||
COPY confs/site/ /opt/confs/site
|
||||
COPY entrypoint/* /opt/entrypoint/
|
||||
COPY autoconf/* /opt/entrypoint/
|
||||
RUN chmod +x /opt/entrypoint/*.py /opt/entrypoint/*.sh
|
||||
|
||||
VOLUME /etc/nginx
|
||||
|
||||
ENTRYPOINT ["/opt/entrypoint/entrypoint.py"]
|
||||
22
autoconf/Dockerfile-arm32v7
Normal file
22
autoconf/Dockerfile-arm32v7
Normal file
@ -0,0 +1,22 @@
|
||||
FROM alpine AS builder
|
||||
|
||||
ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v4.0.0%2Bbalena2/qemu-4.0.0.balena2-arm.tar.gz
|
||||
RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1
|
||||
|
||||
FROM arm32v7/alpine
|
||||
|
||||
COPY --from=builder qemu-arm-static /usr/bin
|
||||
|
||||
RUN apk add py3-pip apache2-utils bash && \
|
||||
pip3 install docker && \
|
||||
mkdir /opt/entrypoint && \
|
||||
mkdir -p /opt/confs/site
|
||||
|
||||
COPY confs/site/ /opt/confs/site
|
||||
COPY entrypoint/* /opt/entrypoint/
|
||||
COPY autoconf/* /opt/entrypoint/
|
||||
RUN chmod +x /opt/entrypoint/*.py /opt/entrypoint/*.sh
|
||||
|
||||
VOLUME /etc/nginx
|
||||
|
||||
ENTRYPOINT ["/opt/entrypoint/entrypoint.py"]
|
||||
22
autoconf/Dockerfile-arm64v8
Normal file
22
autoconf/Dockerfile-arm64v8
Normal file
@ -0,0 +1,22 @@
|
||||
FROM alpine AS builder
|
||||
|
||||
ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v4.0.0%2Bbalena2/qemu-4.0.0.balena2-aarch64.tar.gz
|
||||
RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1
|
||||
|
||||
FROM arm64v8/alpine
|
||||
|
||||
COPY --from=builder qemu-aarch64-static /usr/bin
|
||||
|
||||
RUN apk add py3-pip apache2-utils bash && \
|
||||
pip3 install docker && \
|
||||
mkdir /opt/entrypoint && \
|
||||
mkdir -p /opt/confs/site
|
||||
|
||||
COPY confs/site/ /opt/confs/site
|
||||
COPY entrypoint/* /opt/entrypoint/
|
||||
COPY autoconf/* /opt/entrypoint/
|
||||
RUN chmod +x /opt/entrypoint/*.py /opt/entrypoint/*.sh
|
||||
|
||||
VOLUME /etc/nginx
|
||||
|
||||
ENTRYPOINT ["/opt/entrypoint/entrypoint.py"]
|
||||
15
autoconf/Dockerfile-i386
Normal file
15
autoconf/Dockerfile-i386
Normal file
@ -0,0 +1,15 @@
|
||||
FROM i386/alpine
|
||||
|
||||
RUN apk add py3-pip apache2-utils bash && \
|
||||
pip3 install docker && \
|
||||
mkdir /opt/entrypoint && \
|
||||
mkdir -p /opt/confs/site
|
||||
|
||||
COPY confs/site/ /opt/confs/site
|
||||
COPY entrypoint/* /opt/entrypoint/
|
||||
COPY autoconf/* /opt/entrypoint/
|
||||
RUN chmod +x /opt/entrypoint/*.py /opt/entrypoint/*.sh
|
||||
|
||||
VOLUME /etc/nginx
|
||||
|
||||
ENTRYPOINT ["/opt/entrypoint/entrypoint.py"]
|
||||
@ -1,101 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import docker, datetime, subprocess, shutil, os
|
||||
|
||||
def log(event) :
|
||||
print("[" + str(datetime.datetime.now().replace(microsecond=0)) + "] AUTOCONF - " + event, flush=True)
|
||||
|
||||
def replace_in_file(file, old_str, new_str) :
|
||||
with open(file) as f :
|
||||
data = f.read()
|
||||
data = data[::-1].replace(old_str[::-1], new_str[::-1], 1)[::-1]
|
||||
with open(file, "w") as f :
|
||||
f.write(data)
|
||||
|
||||
def generate(vars) :
|
||||
vars_defaults = vars.copy()
|
||||
vars_defaults.update(os.environ)
|
||||
vars_defaults.update(vars)
|
||||
subprocess.run(["/opt/entrypoint/site-config.sh", vars["SERVER_NAME"]], env=vars_defaults)
|
||||
log("Generated config for " + vars["SERVER_NAME"])
|
||||
|
||||
def activate(vars) :
|
||||
replace_in_file("/etc/nginx/nginx.conf", "}", "include /etc/nginx/" + vars["SERVER_NAME"] + "/server.conf;\n}")
|
||||
subprocess.run(["/usr/sbin/nginx", "-s", "reload"])
|
||||
log("Activated config for " + vars["SERVER_NAME"])
|
||||
|
||||
def deactivate(vars) :
|
||||
replace_in_file("/etc/nginx/nginx.conf", "include /etc/nginx/" + vars["SERVER_NAME"] + "/server.conf;\n", "")
|
||||
subprocess.run(["/usr/sbin/nginx", "-s", "reload"])
|
||||
log("Deactivated config for " + vars["SERVER_NAME"])
|
||||
|
||||
def remove(vars) :
|
||||
shutil.rmtree("/etc/nginx/" + vars["SERVER_NAME"])
|
||||
log("Removed config for " + vars["SERVER_NAME"])
|
||||
|
||||
def process(id, event, vars) :
|
||||
global containers
|
||||
if event == "create" :
|
||||
generate(vars)
|
||||
containers.append(id)
|
||||
elif event == "start" :
|
||||
activate(vars)
|
||||
elif event == "die" :
|
||||
deactivate(vars)
|
||||
elif event == "destroy" :
|
||||
remove(vars)
|
||||
containers.remove(id)
|
||||
|
||||
containers = []
|
||||
|
||||
client = docker.DockerClient(base_url='unix:///var/run/docker.sock')
|
||||
|
||||
# Process containers created before
|
||||
for container in client.containers.list(all=True, filters={"label" : "bunkerized-nginx.SERVER_NAME"}) :
|
||||
|
||||
# Extract bunkerized-nginx.* labels
|
||||
labels = container.labels.copy()
|
||||
for label in container.labels :
|
||||
if not label.startswith("bunkerized-nginx.") :
|
||||
del labels[label]
|
||||
# Remove bunkerized-nginx. on labels
|
||||
vars = { k.replace("bunkerized-nginx.", "", 1) : v for k, v in labels.items()}
|
||||
|
||||
# Container is restarting or running
|
||||
if container.status == "restarting" or container.status == "running" :
|
||||
process(container.id, "create", vars)
|
||||
process(container.id, "start", vars)
|
||||
|
||||
# Container is created or exited
|
||||
if container.status == "created" or container.status == "exited" :
|
||||
process(container.id, "create", vars)
|
||||
|
||||
for event in client.events(decode=True) :
|
||||
|
||||
# Process only container events
|
||||
if event["Type"] != "container" :
|
||||
continue
|
||||
|
||||
# Check if a bunkerized-nginx.* label is present
|
||||
present = False
|
||||
for label in event["Actor"]["Attributes"] :
|
||||
if label.startswith("bunkerized-nginx.") :
|
||||
present = True
|
||||
break
|
||||
if not present :
|
||||
continue
|
||||
|
||||
# Only process if we generated a config
|
||||
if not event["id"] in containers and event["Action"] != "create" :
|
||||
continue
|
||||
|
||||
# Extract bunkerized-nginx.* labels
|
||||
labels = event["Actor"]["Attributes"].copy()
|
||||
for label in event["Actor"]["Attributes"] :
|
||||
if not label.startswith("bunkerized-nginx.") :
|
||||
del labels[label]
|
||||
# Remove bunkerized-nginx. on labels
|
||||
vars = { k.replace("bunkerized-nginx.", "", 1) : v for k, v in labels.items()}
|
||||
|
||||
# Process the event
|
||||
process(event["id"], event["Action"], vars)
|
||||
@ -111,14 +111,6 @@ if [ "$1" == "test" ] ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# start the autoconf manager
|
||||
if [ -S "/var/run/docker.sock" ] ; then
|
||||
echo "[*] Running autoconf ..."
|
||||
touch /var/log/autoconf.log
|
||||
/opt/autoconf/autoconf.py > /var/log/autoconf.log 2>&1 &
|
||||
LOGS="$LOGS /var/log/autoconf.log"
|
||||
fi
|
||||
|
||||
# display logs
|
||||
tail -F $LOGS &
|
||||
wait $!
|
||||
|
||||
@ -3,10 +3,12 @@
|
||||
curl -Lo manifest-tool https://github.com/estesp/manifest-tool/releases/download/v1.0.3/manifest-tool-linux-amd64
|
||||
chmod +x manifest-tool
|
||||
|
||||
VERSION=$(cat VERSION | tr -d '\n')
|
||||
if [ "$SOURCE_BRANCH" = "dev" ] ; then
|
||||
./manifest-tool push from-args --ignore-missing --platforms linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8 --template bunkerity/bunkerized-nginx:dev-ARCHVARIANT --target bunkerity/bunkerized-nginx:dev
|
||||
elif [ "$SOURCE_BRANCH" = "master" ] ; then
|
||||
./manifest-tool push from-args --ignore-missing --platforms linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8 --template bunkerity/bunkerized-nginx:ARCHVARIANT --target bunkerity/bunkerized-nginx:${VERSION}
|
||||
./manifest-tool push from-args --ignore-missing --platforms linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8 --template bunkerity/bunkerized-nginx:ARCHVARIANT --target bunkerity/bunkerized-nginx:latest
|
||||
fi
|
||||
echo "$DOCKER_REPO"
|
||||
|
||||
#VERSION=$(cat VERSION | tr -d '\n')
|
||||
#if [ "$SOURCE_BRANCH" = "dev" ] ; then
|
||||
# ./manifest-tool push from-args --ignore-missing --platforms linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8 --template bunkerity/bunkerized-nginx:dev-ARCHVARIANT --target bunkerity/bunkerized-nginx:dev
|
||||
#elif [ "$SOURCE_BRANCH" = "master" ] ; then
|
||||
# ./manifest-tool push from-args --ignore-missing --platforms linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8 --template bunkerity/bunkerized-nginx:ARCHVARIANT --target bunkerity/bunkerized-nginx:${VERSION}
|
||||
# ./manifest-tool push from-args --ignore-missing --platforms linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8 --template bunkerity/bunkerized-nginx:ARCHVARIANT --target bunkerity/bunkerized-nginx:latest
|
||||
#fi
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Register qemu-*-static for all supported processors except the
|
||||
# Register qemu-*-static for all supported processors except the
|
||||
# current one, but also remove all registered binfmt_misc before
|
||||
docker run --rm --privileged multiarch/qemu-user-static:register --reset
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user