diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..368be9a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +.calva +.lsp +tmp +tmp-* +.lein-env +.nrepl-port +*.md +!README*.md \ No newline at end of file diff --git a/.gitignore b/.gitignore index 76ba698..37c7a33 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,6 @@ pom.xml.asc /test-resources/pcp.edn /data /musketeers.js -/test.js \ No newline at end of file +/test.js +.calva/ +.lsp \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b9fd612 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Multi stage image for building pcp +# Stage 1: build pcp +FROM ghcr.io/graalvm/graalvm-ce:java8-21.0.0.2 as build + +RUN curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein --output /usr/local/bin/lein && \ + chmod a+x /usr/local/bin/lein && \ + gu install native-image + +COPY . /app-src +WORKDIR /app-src + +RUN bash build.sh && \ + ls -la target/ + +# Stage 2: final image +FROM adoptopenjdk:8-jre-hotspot-focal + +COPY --from=build /app-src/target/pcp* /usr/local/bin/ +COPY docker-entrypoint.sh /docker-entrypoint.sh + +COPY resources/pcp-templates /usr/share/pcp-site + +EXPOSE 9000 +EXPOSE 3000 + +CMD ["/docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..4067b54 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# + +# turn on bash's job control +set -m + +# Start the primary process and put it in the background +java -jar /usr/local/bin/pcp-server.jar & + +# Start the helper process +/usr/local/bin/pcp -s /usr/share/pcp-site + +# now we bring the primary process back into the foreground +# and leave it there +fg %1 \ No newline at end of file diff --git a/docs/pcp-container.md b/docs/pcp-container.md new file mode 100644 index 0000000..3bf8e36 --- /dev/null +++ b/docs/pcp-container.md @@ -0,0 +1,44 @@ +# Running PCP using containers + +You can run `pcp` using container orchestrators + +* Docker +* podman +* [TODO] Kubernetes + +## Building container image using docker/podman + + +```sh + # Build the pcp container + docker build -t pcp . +``` + +## Using pcp container + +You can run the container as is: + +```sh + # Use the container using the default site + docker run --rm -ti -p 3000:3000 pcp + + # Mount your site in the container. Once it starts, you can edit files and refresh. + docker run --rm -ti -p 3000:3000 -v examples/netdava-test/public:/usr/share/pcp-site pcp +``` + +You can build a custom container from pcp with your site. + +```sh + +cat > mysite.dockerfile << EOF +FROM pcp:latest +COPY my-webiste /usr/share/pcp-site +EOF + +# Build the custom image +docker build -t my-pcp-site:latest -f mysite.dockerfile . +# Run your website + +docker run --name my-pcp-site -p 3000:3000 my-pcp-site:latest +``` + diff --git a/project.clj b/project.clj index 73eedcc..e61f5d8 100644 --- a/project.clj +++ b/project.clj @@ -65,7 +65,8 @@ :uberjar-name "pcp.jar"} :test {:env {:my-passphrase "s3cr3t-p455ph4r3" :pcp-template-path "resources/pcp-templates"}} - :dev {:dependencies [[eftest/eftest "0.5.9"]] + :dev {:dependencies [[eftest/eftest "0.5.9"] + [org.slf4j/slf4j-simple "1.7.32"]] :plugins [[lein-shell "0.5.0"]] :env {:my-passphrase "s3cr3t-p455ph4r3"}}} :aliases