diff --git a/docker/Dockerfile b/docker/Dockerfile index 0e162ff..8d17938 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,6 +2,7 @@ FROM node:20-alpine WORKDIR /usr/src/app +RUN apk add --no-cache bash RUN apk add --no-cache gawk # Copy and install dependencies @@ -18,4 +19,7 @@ RUN npm run build RUN npm i -g pm2 RUN cp ecosystem.example.json ecosystem.config.json -CMD pm2-runtime ecosystem.config.json +## Make Docker-related scripts available in root folder +COPY docker/*.sh . + +CMD ["bash", "entrypoint.sh"] diff --git a/docker/build.sh b/docker/build.sh new file mode 100644 index 0000000..2e5104b --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# We need to rebuild the front-end if $BASE changed + +base_file=dist/.base + +if [[ -e $base_file && "$BASE" == "$(cat $base_file)" ]] || [[ ! -e $base_file && "$BASE" == "" ]]; then + echo "Front-end rebuild skipped." +else + echo "Rebuilding front-end because \$BASE changed to $BASE..." + # Build the site + npm run build + # Remember the current $BASE + echo "$BASE" > $base_file +fi diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..0634130 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Build site in background +bash build.sh & + +pm2-runtime ecosystem.config.json