Skip to content

Commit

Permalink
Fix #1521: Push images to GHCR (#1522)
Browse files Browse the repository at this point in the history
  • Loading branch information
lispyclouds committed Mar 15, 2023
1 parent e2f2e9a commit e752111
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
25 changes: 24 additions & 1 deletion .circleci/script/docker.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

(def image-name "babashka/babashka")

(def ghcr-image-name "ghcr.io/babashka/babashka")

(def image-tag (str/trim (slurp "resources/BABASHKA_VERSION")))

(def latest-tag "latest")
Expand Down Expand Up @@ -46,6 +48,11 @@
[username password]
(exec ["docker" "login" "-u" username "-p" password]))

(defn docker-login-ghcr
[username password]
(exec ["docker" "login" "ghcr.io" "-u" username "-p" password]))

;; TODO: Remove this when Dockerhub goes off
(defn build-push
[image-tag platform docker-file]
(println (format "Building and pushing %s Docker image(s) %s:%s"
Expand All @@ -59,6 +66,19 @@
"-f" docker-file]]
(exec (concat base-cmd label-args ["."]))))

(defn build-push-ghcr
[image-tag platform docker-file]
(println (format "Building and pushing %s Docker image(s) %s:%s to GHCR"
platform
ghcr-image-name
image-tag))
(let [base-cmd ["docker" "buildx" "build"
"-t" (str ghcr-image-name ":" image-tag)
"--platform" platform
"--push"
"-f" docker-file]]
(exec (concat base-cmd label-args ["."]))))

(defn build-push-images
[]
(doseq [platform (str/split platforms #",")]
Expand All @@ -74,8 +94,10 @@
; this overwrites, but this is to work around having built the uberjar/metabom multiple times
(fs/copy (format "/tmp/release/%s-metabom.jar" tarball-platform) "metabom.jar" {:replace-existing true})))
(build-push image-tag platforms "Dockerfile.ci")
(build-push-ghcr image-tag platforms "Dockerfile.ci")
(when-not snapshot?
(build-push latest-tag platforms "Dockerfile.ci")))
(build-push latest-tag platforms "Dockerfile.ci")
(build-push-ghcr latest-tag platforms "Dockerfile.ci")))

(defn build-push-alpine-images
"Build alpine image for linux-amd64 only (no upstream arm64 support yet)"
Expand All @@ -93,6 +115,7 @@
(println "This is a snapshot version")
(println "This is a non-snapshot version"))
(docker-login (read-env "DOCKERHUB_USER") (read-env "DOCKERHUB_PASS"))
(docker-login-ghcr (read-env "CONTAINER_REGISTRY_USER") (read-env "BB_GHCR_TOKEN"))
(build-push-images)
(build-push-alpine-images))
(println "Not publishing docker image(s).")))
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ A preview of the next release can be installed from
- [#1507](https://github.com/babashka/babashka/issues/1507): Expose methods on java.lang.VirtualThread ([@lispyclouds](https://github.com/lispyclouds))
- [#1510](https://github.com/babashka/babashka/issues/1510): add virtual thread interop on `Thread`
- [#1511](https://github.com/babashka/babashka/issues/1511): support domain sockets
- [#1521](https://github.com/babashka/babashka/issues/1521): push images to GHCR ([@lispyclouds](https://github.com/lispyclouds))

## 1.2.174 (2023-03-01)

Expand Down

0 comments on commit e752111

Please sign in to comment.