Skip to content

Commit f516603

Browse files
pacman-ghostPacman Ghost
andauthored
Fixed the Dockerfile to work with Node 20. (#471)
Co-authored-by: Pacman Ghost <[email protected]>
1 parent 648e90c commit f516603

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# NOTE: We create a temporary Docker container to build the webapp in, then copy
2+
# the generated distributable files to the final Docker image. This keeps the
3+
# final image tidy (since it doesn't contain any generated temporary artifacts),
4+
# and its size to a minimum.
5+
# NOTE: The version of Node must be kept in sync with what's in package.json.
6+
FROM node:20-alpine AS build
7+
8+
# build the webapp
9+
WORKDIR /app/
10+
COPY package.json .
11+
RUN npm install
12+
COPY . .
13+
RUN npm run build
14+
15+
# create the final Docker image
16+
# NOTE: The webapp is just a bunch of static files, so all we need is something to serve them.
17+
FROM nginx:1.27-alpine
18+
COPY docker/nginx-default.conf /etc/nginx/conf.d/default.conf
19+
COPY --from=build /app/dist /app
20+
21+
EXPOSE 80
22+
CMD [ "nginx", "-g", "daemon off;" ]

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"description": "Emulate a BBC Micro",
99
"repository": "[email protected]:mattgodbolt/jsbeeb.git",
1010
"version": "0.0.7",
11+
"//": "If you change the version of Node, it must also be updated at the top of the Dockerfile.",
1112
"engines": {
1213
"node": "20"
1314
},

run-container.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
# Helper script that builds and launches the Docker container.
3+
4+
# ---------------------------------------------------------------------
5+
6+
function main
7+
{
8+
# initialize
9+
cd `dirname "$0"`
10+
PORT=8271
11+
IMAGE_TAG=latest
12+
CONTAINER_NAME=jsbeeb
13+
DETACH=
14+
NO_BUILD=
15+
16+
# parse the command-line arguments
17+
if [ $# -eq 0 ]; then
18+
print_help
19+
exit 0
20+
fi
21+
params="$(getopt -o p:t:d -l port:,tag:,name:,detach,,no-build,help --name "$0" -- "$@")"
22+
if [ $? -ne 0 ]; then exit 1; fi
23+
eval set -- "$params"
24+
while true; do
25+
case "$1" in
26+
-p | --port)
27+
PORT=$2
28+
shift 2 ;;
29+
-t | --tag)
30+
IMAGE_TAG=$2
31+
shift 2 ;;
32+
--name)
33+
CONTAINER_NAME=$2
34+
shift 2 ;;
35+
-d | --detach )
36+
DETACH=--detach
37+
shift 1 ;;
38+
--no-build )
39+
NO_BUILD=1
40+
shift 1 ;;
41+
--help )
42+
print_help
43+
exit 0 ;;
44+
-- ) shift ; break ;;
45+
* )
46+
echo "Unknown option: $1" >&2
47+
exit 1 ;;
48+
esac
49+
done
50+
51+
# build the image
52+
if [ -z "$NO_BUILD" ]; then
53+
echo Building the \"$IMAGE_TAG\" image...
54+
docker build \
55+
--tag jsbeeb:$IMAGE_TAG \
56+
. 2>&1 \
57+
| sed -e 's/^/ /'
58+
if [ ${PIPESTATUS[0]} -ne 0 ]; then exit 10 ; fi
59+
echo
60+
fi
61+
62+
# launch the container
63+
echo Launching the \"$IMAGE_TAG\" image as \"$CONTAINER_NAME\"...
64+
docker run \
65+
--name $CONTAINER_NAME \
66+
--publish $PORT:80 \
67+
$DETACH \
68+
-it --rm \
69+
jsbeeb:$IMAGE_TAG \
70+
2>&1 \
71+
| sed -e 's/^/ /'
72+
exit ${PIPESTATUS[0]}
73+
}
74+
75+
# ---------------------------------------------------------------------
76+
77+
function print_help {
78+
echo "`basename "$0"` {options}"
79+
cat <<EOM
80+
Build and launch the "jsbeeb" container.
81+
82+
-p --port Web server port number.
83+
-t --tag Docker image tag.
84+
--name Docker container name.
85+
-d --detach Detach from the container and let it run in the background.
86+
--no-build Launch the container as-is (i.e. without rebuilding the image first).
87+
EOM
88+
}
89+
90+
# ---------------------------------------------------------------------
91+
92+
main "$@"

0 commit comments

Comments
 (0)