Fix #1521: Push images to GHCR (#1522)

This commit is contained in:
Rahuλ Dé 2023-03-15 15:52:05 +00:00 committed by GitHub
parent e2f2e9ae4e
commit e7521110c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View file

@ -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")
@ -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"
@ -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 #",")]
@ -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)"
@ -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).")))

View file

@ -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)