get docker deploy working

This commit is contained in:
Travis Shears 2025-07-26 10:35:55 +02:00
parent 7e0659cebe
commit 637bb6740c
10 changed files with 101 additions and 23 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
target/
node_modules
.serverless
.env
@ -6,5 +7,5 @@ nostr/*
dist
.clj-kondo/
.lsp/
config.edn
.cpcache
.env

43
Dockerfile Normal file
View file

@ -0,0 +1,43 @@
# The default deploy instructions (https://biffweb.com/docs/reference/production/) don't
# use Docker, but this file is provided in case you'd like to deploy with containers.
#
# When running the container, make sure you set any environment variables defined in config.env,
# e.g. using whatever tools your deployment platform provides for setting environment variables.
#
# Run these commands to test this file locally:
#
# docker build -t your-app .
# docker run --rm -e BIFF_PROFILE=dev -v $PWD/config.env:/app/config.env your-app
# This is the base builder image, construct the jar file in this one
# it uses alpine for a small image
FROM clojure:temurin-21-tools-deps-alpine AS jre-build
# Install the missing packages and applications in a single layer
RUN apk add curl rlwrap
WORKDIR /app
COPY deps.edn ./
RUN clj -P
COPY build.clj config.edn ./
COPY src ./src
# construct the application jar
RUN clj -T:build uber && cp target/micro-blog-standalone.jar ./app.jar && rm -r target
# This stage (see multi-stage builds) is a bare Java container
# copy over the uberjar from the builder image and run the application
FROM eclipse-temurin:21-alpine
WORKDIR /app
# Take the uberjar from the base image and put it in the final image
COPY --from=jre-build /app/app.jar /app/app.jar
COPY --from=jre-build /app/config.edn /app/
EXPOSE 8080
# By default, run in PROD profile
# ENV BIFF_PROFILE=prod
ENV HOST=0.0.0.0
ENV PORT=8080
CMD ["/opt/java/openjdk/bin/java", "-XX:-OmitStackTraceInFastThrow", "-XX:+CrashOnOutOfMemoryError", "-jar", "app.jar"]

View file

@ -17,7 +17,24 @@ instance.
## Deployment
TODO
Repl:
```shell
$ clj
```
Build and run uber jar manually:
```shell
$ clj -T:build uber
$ java -jar ./target/micro-blog-standalone.jar
```
Build new docker image and push it to ECR
```shell
$ docker buildx build --platform linux/amd64,linux/arm64 -t 853019563312.dkr.ecr.eu-central-1.amazonaws.com/micro-blog-fetchers:2.0.1 --push .
```
## Project history

View file

@ -1,7 +1,7 @@
(ns build
(:require [clojure.tools.build.api :as b]))
(def lib 'snippets)
(def lib 'micro-blog)
(def class-dir "target/classes")
(def uber-file (format "target/%s-standalone.jar" (name lib)))
@ -17,9 +17,9 @@
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})
(b/compile-clj {:basis @basis
:ns-compile '[snippets.main]
:ns-compile '[micro-blog.main]
:class-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file uber-file
:basis @basis
:main 'snippets.main}))
:main 'micro-blog.main}))

8
config.edn Normal file
View file

@ -0,0 +1,8 @@
{:mistral-agent-id "ag:e4f9e422:20250716:ismicroblogposttech:99ac9759"
:mistral-host "https://api.mistral.ai"
:pocket-base-user "micro_blog_fetchers"
:pocket-base-host "http://aemos:5000"
:blue-sky-host "https://bsky.social/xrpc"
:blue-sky-username "travisshears.bsky.social"}

View file

@ -1,10 +0,0 @@
{:mistral-api-key "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
:mistral-agent-id "ag:xxxxxxxx:xxxxxxxx:xxxxxxxxxxxxxxxxxxx:xxxxxxxx"
:mistral-host "https://api.mistral.ai"
:pocket-base-pw "xxxxxxxx"
:pocket-base-user "xxxxxxxxxxxxxxxxxxx"
:pocket-base-host "xxxxxxxxxxxxx"
:blue-sky-api-key "xxxxxxxxxxxxxxxxxxx"
:blue-sky-username "coolguy.bsky.social"}

View file

@ -2,10 +2,11 @@
:deps {clj-http/clj-http {:mvn/version "3.13.1"}
;; logging
com.taoensso/telemere {:mvn/version "1.0.0"}
;; environment variables
environ/environ {:mvn/version "1.2.0"}
;; schema validation
metosin/malli {:mvn/version "0.18.0"}
;; scheduling
jarohen/chime {:mvn/version "0.3.3"}
org.clojure/core.async {:mvn/version "1.8.741"}
;; json decoding
cheshire/cheshire {:mvn/version "6.0.0"}
;; metosin/muuntaja {:mvn/version "0.6.11"}

View file

@ -3,8 +3,7 @@
[clj-http.client :as http-client]
[micro-blog.pocket-base :as pb]
[micro-blog.utils :as utils]
[malli.core :as m]
[clojure.pprint :refer [pprint]]
[taoensso.telemere :as tel]
[micro-blog.config :refer [config]]))
(defn create-session []
@ -97,6 +96,7 @@
(map #(vector (:fullsize %) (:alt %)) images)))
(defn run []
(tel/log! :info "Running blue sky fetcher")
(let [session (create-session)
last-saved-id (pb/get-latest-post-remote-id-by-source :blue_sky)
new-posts (reverse (get-posts-until-id session last-saved-id))]

View file

@ -1,14 +1,18 @@
(ns micro-blog.config
(:require [environ.core :refer [env]]))
(:require
[taoensso.telemere :as tel]))
(def ^:private env-overrides
{:minstral-api-key "MISTRAL_API_KEY"})
{:pocket-base-pw "POCKET_BASE_PW"
:pocket-base-host "POCKET_BASE_HOST"
:blue-sky-api-key "BLUE_SKY_API_KEY"
:minstral-api-key "MISTRAL_API_KEY"})
(defn- load-config []
(println "config is being loaded")
(tel/log! :info "Config is being loaded")
(merge (read-string (slurp "config.edn"))
(into {} (for [[k env-var] env-overrides
:let [env-val (env env-var)]
:let [env-val (System/getenv env-var)]
:when env-val]
[k env-val]))))

14
src/micro_blog/main.clj Normal file
View file

@ -0,0 +1,14 @@
(ns micro-blog.main
(:gen-class)
(:import [java.time Instant Duration])
(:require [chime.core :as chime]
[taoensso.telemere :as tel]
[micro-blog.blue-sky :as blue-sky]))
(defn -main []
(tel/log! :info "Setting up crons")
(chime/chime-at (chime/periodic-seq (Instant/now) (Duration/ofMinutes 30))
(fn [_time]
(blue-sky/run)))
@(promise))