From 57c38f5457f496998580d89a2dd8857137889c84 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 9 Jul 2023 23:55:45 -0400 Subject: [PATCH] Add nginx to dockerfile and deploy a static index.html. --- docker/server/Dockerfile | 12 ++++++++---- docker/server/Makefile | 35 +++++++++++++++++++++++++++++++++++ docker/server/nginx.conf | 40 ++++++++++++++++++++++++++++++++++++++++ static/index.html | 5 +++++ 4 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 docker/server/Makefile create mode 100644 docker/server/nginx.conf create mode 100644 static/index.html diff --git a/docker/server/Dockerfile b/docker/server/Dockerfile index bf4e538..5d25077 100644 --- a/docker/server/Dockerfile +++ b/docker/server/Dockerfile @@ -1,6 +1,10 @@ -FROM harbor.fizz.buzz/dockerhub/library/python:3.9 +FROM harbor.fizz.buzz/dockerhub/library/alpine:3.18 -RUN useradd -m -g nogroup server -USER server +RUN apk add --no-cache bash nginx +RUN addgroup web && adduser -D -G web web && install -d -D -o web -g web -m 700 /srv/http/public +RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log -CMD ["python", "-c", "print('worked')"] +COPY --chown=web:web docker/nginx.conf /srv/http +COPY --chown=web:web static/ /srv/http/public/ + +ENTRYPOINT ["/usr/sbin/nginx", "-c", "/srv/http/nginx.conf", "-e", "stderr", "-g", "daemon off;"] diff --git a/docker/server/Makefile b/docker/server/Makefile new file mode 100644 index 0000000..ef9d75e --- /dev/null +++ b/docker/server/Makefile @@ -0,0 +1,35 @@ +IMAGE_NAME:=homepage +# REMOTE_REPO:=harbor.fizz.buzz/private + +.PHONY: all +all: build push + +.PHONY: build +build: + docker build -t $(IMAGE_NAME) -f Dockerfile ../ + +.PHONY: push +push: +ifdef REMOTE_REPO + docker tag $(IMAGE_NAME) $(REMOTE_REPO)/$(IMAGE_NAME) + docker push $(REMOTE_REPO)/$(IMAGE_NAME) +else + @echo "REMOTE_REPO not defined, not pushing to a remote repo." +endif + +.PHONY: clean +clean: + docker rmi $(IMAGE_NAME) +ifdef REMOTE_REPO + docker rmi $(REMOTE_REPO)/$(IMAGE_NAME) +else + @echo "REMOTE_REPO not defined, not removing from remote repo." +endif + +.PHONY: run +run: + docker run --rm -i -t -p "8080:8080" $(IMAGE_NAME) + +.PHONY: shell +shell: + docker run --rm -i -t -p "8080:8080" --entrypoint /bin/bash $(IMAGE_NAME) diff --git a/docker/server/nginx.conf b/docker/server/nginx.conf new file mode 100644 index 0000000..61a40e8 --- /dev/null +++ b/docker/server/nginx.conf @@ -0,0 +1,40 @@ +user web; +worker_processes 4; + +# Speed up regular expressions. +pcre_jit on; + +error_log stderr debug; + +events { + # Connections per worker process. + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + server_tokens off; + client_max_body_size 1m; + sendfile on; + tcp_nopush on; + + server { + listen 8080; + root /srv/http/public; + + location / { + index index.html index.htm; + if (-d $request_filename) { + rewrite [^/]$ $http_x_forwarded_proto://$http_host$uri/ redirect; + } + } + + location /healthz { + access_log off; + add_header 'Content-Type' 'application/json'; + return 200 '{"status":"OK"}'; + } + } + +} diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..3043fad --- /dev/null +++ b/static/index.html @@ -0,0 +1,5 @@ + + + Coming Eventually! + +