From 965e503aec51c7501511ea614a5c73feaa631627 Mon Sep 17 00:00:00 2001 From: Sven Strittmatter Date: Tue, 6 Jun 2023 21:48:29 +0200 Subject: [PATCH 1/2] Adds Dockerfile to build a container image which hosts diceware The container is built in two steps (docker builder pattern): 1. Node/npm build stage 2. Final image with Nginx and static files to serve Build the mage with this command: docker image build -t dceware . Run a container with this command: docker run --rm -p 8080:80 dceware Then you can visit your local diceware at: http://localhost:8080/ Signed-off-by: Sven Strittmatter --- Dockerfile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..722fe7b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:20-bullseye-slim as builder + +RUN mkdir /tmp/diceware +COPY . /tmp/diceware/ +WORKDIR /tmp/diceware + +RUN npm run build + +FROM nginx:1.25-bullseye + +COPY --from=builder /tmp/diceware/assets /usr/share/nginx/html/assets/ +COPY --from=builder /tmp/diceware/dist /usr/share/nginx/html/dist/ +COPY --from=builder /tmp/diceware/fonts /usr/share/nginx/html/fonts +COPY --from=builder /tmp/diceware/favicon.ico /usr/share/nginx/html/favicon.ico +COPY --from=builder /tmp/diceware/index.html /usr/share/nginx/html/index.html +COPY --from=builder /tmp/diceware/robots.txt /usr/share/nginx/html/robots.txt + +RUN chmod -R a+rX /usr/share/nginx/html From 0a93c9e8c4ae3c457235b79a4ba8799338c44871 Mon Sep 17 00:00:00 2001 From: Douglas Muth Date: Sat, 10 Jun 2023 12:54:19 -0400 Subject: [PATCH 2/2] Added Docker support --- Dockerfile | 1 + README.md | 10 ++++++++++ bin/docker-build.sh | 13 +++++++++++++ bin/docker-dev.sh | 16 ++++++++++++++++ bin/docker-prod.sh | 13 +++++++++++++ bin/docker-push.sh | 15 +++++++++++++++ 6 files changed, 68 insertions(+) create mode 100755 bin/docker-build.sh create mode 100755 bin/docker-dev.sh create mode 100755 bin/docker-prod.sh create mode 100755 bin/docker-push.sh diff --git a/Dockerfile b/Dockerfile index 722fe7b..e8beac6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,3 +16,4 @@ COPY --from=builder /tmp/diceware/index.html /usr/share/nginx/html/index.html COPY --from=builder /tmp/diceware/robots.txt /usr/share/nginx/html/robots.txt RUN chmod -R a+rX /usr/share/nginx/html + diff --git a/README.md b/README.md index ae95518..bea3288 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,16 @@ A local webserver can be set up by running `npm install http-server -g` to insta - `gh release upload v1.0.1 diceware.zip` to upload the ZIP file containing everything +## Development In Docker + +Wanna develop in Docker? We got you covered. Here are some helper scripts: + +- `bin/docker-build.sh` - Build the Docker copntainer +- `bin/docker-dev.sh` - Run in dev mode--listening on http://localhost:8000/ +- `bin/docker-prod.sh` - Run in prod mode--listening on http://localhost:80/ +- `bin/docker-push.sh` - Push to Docker Hub + + # Who built this? / Contact My name is Douglas Muth, and I am a software engineer in Philadelphia, PA. diff --git a/bin/docker-build.sh b/bin/docker-build.sh new file mode 100755 index 0000000..a13ffc6 --- /dev/null +++ b/bin/docker-build.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# +# Build our Docker image. +# + +# Errors are fatal +set -e + +# Change to the parent directory of this script +pushd $(dirname $0)/.. > /dev/null + +docker build -t diceware . -f ./Dockerfile + diff --git a/bin/docker-dev.sh b/bin/docker-dev.sh new file mode 100755 index 0000000..a25a872 --- /dev/null +++ b/bin/docker-dev.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Script to run the script in dev mode, which will spawn a shell +# + +# Errors are fatal +set -e + +# Change to the parent directory +pushd $(dirname $0)/.. > /dev/null + +PORT=${PORT:=8000} + +docker run --rm -it -p ${PORT}:80 -v $(pwd):/mnt diceware + + diff --git a/bin/docker-prod.sh b/bin/docker-prod.sh new file mode 100755 index 0000000..bb9fb3b --- /dev/null +++ b/bin/docker-prod.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# +# Script to run the script in prod mode +# + +# Errors are fatal +set -e + +# Change to the parent directory +pushd $(dirname $0)/.. > /dev/null + +docker run --rm -p 80:80 diceware + diff --git a/bin/docker-push.sh b/bin/docker-push.sh new file mode 100755 index 0000000..2f4b320 --- /dev/null +++ b/bin/docker-push.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# +# Push our Docker image our Docker Hub. +# + +# Errors are fatal +set -e + +# Change to the parent directory of this script +pushd $(dirname $0)/.. > /dev/null + +docker tag diceware dmuth1/diceware +docker push dmuth1/diceware + +