diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e8beac6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +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 + 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 + +