Add multi stage dockerfile and fix source URL

This commit is contained in:
Aaron Fischer 2021-02-18 02:00:03 +01:00
parent 81d0904a3b
commit 1c7af9ebcc
3 changed files with 29 additions and 6 deletions

View file

@ -1,6 +1,14 @@
FROM java:8
FROM clojure:openjdk-16-alpine AS builder
RUN mkdir -p /app
WORKDIR /app
COPY project.clj /app
RUN lein deps
COPY . /app
RUN mv "$(lein uberjar | sed -n 's/^Created \(.*standalone\.jar\)/\1/p')" app-standalone.jar
ADD buchdesmonats-1.7.jar /buchdesmonats/
WORKDIR /buchdesmonats
CMD ["java", "-jar", "buchdesmonats-1.7.jar"]
FROM openjdk:16
RUN mkdir -p /app/public
WORKDIR /app
COPY --from=builder /app/app-standalone.jar /app/bdm.jar
# Make sure you mount the public folder
CMD java -jar bdm.jar $TYPE

View file

@ -11,6 +11,21 @@ list. This includes books and comics.
$ target/buchdesmonats-1.7-standalone.jar [book|comic]
## Docker
You can use the Dockerfile to generate the static content. This is useful
for a cronjob. You want to mount the target dir, so it is not lost after
the container stops. The Dockerfile is a multi stage dockerfile, which
first compiles the clojure files into a standalone jar file and then use
it to generate the book of the month content.
$ docker build . -t bdm:1.7
Run this periodically:
$ docker run -it -v "$PWD/public:/app/public" -e "TYPE=book" bdm:1.7
$ docker run -it -v "$PWD/public:/app/public" -e "TYPE=comic" bdm:1.7
## Authors
* Programming: [Aaron Fischer](https://aaron-fischer.net/)

View file

@ -81,7 +81,7 @@
(defn -main [& args]
(let [type (first args)
datasource-url (str "https://git.okoyono.de/mezzomix/buch_des_monats/raw/master/" (clojure.string/upper-case type) ".mkd")
datasource-url (str "https://git.okoyono.de/mezzo/buch_des_monats/raw/master/" (clojure.string/upper-case type) ".mkd")
target-dir (io/file "public" (str type "-covers"))]
(fs/mkdirs target-dir)
(generate-html type (scrape-book-urls datasource-url) "public")