diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4ee7034 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +**/node_modules +**/build +**/Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3e5f379 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# stage 1: build node frontend +FROM node:21 as node-builder + +WORKDIR /node-builder +COPY ./public ./public +COPY ./src ./src +COPY ./package.json . +COPY ./package-lock.json . +COPY ./tsconfig.json . + +RUN \ + npm install && \ + npm run build + + +FROM busybox:1.36-musl + +RUN adduser -D pingator +USER pingator +WORKDIR /www + +COPY --from=node-builder /node-builder/build /www + +# Run BusyBox httpd +CMD ["busybox", "httpd", "-f", "-v", "-h", "/www", "-p", "3000"] diff --git a/Makefile b/Makefile index 5c26a72..6e1d7b5 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +CONTAINER_NAME=pingator +IMAGE_NAME=pingator +EXTERNAL_PORT=8080 + run: @npm start @@ -6,3 +10,19 @@ build: - @rm -rf build @npm run build @rm build/static/js/*.map + +docker-build: + - @docker image rm $(IMAGE_NAME) + @docker \ + build \ + --progress plain \ + --tag $(IMAGE_NAME) \ + . + +docker-run: + @docker \ + run \ + --publish $(EXTERNAL_PORT):3000 \ + --name=$(CONTAINER_NAME) \ + --detach \ + $(IMAGE_NAME)