-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add native image builds for linux and macos (#690)
* ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases * fixup! ci: add native-image builds and releases
- Loading branch information
1 parent
099d8ba
commit 7428d0a
Showing
10 changed files
with
338 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
(ns gen-ci | ||
(:require | ||
[babashka.tasks :as tasks] | ||
[clj-yaml.core :as yaml] | ||
[clojure.string :as str] | ||
[flatland.ordered.map :refer [ordered-map]])) | ||
|
||
(def graalvm-version "22.0.2") | ||
|
||
(defn run | ||
([cmd-name cmd] | ||
(run cmd-name cmd nil)) | ||
([cmd-name cmd no-output-timeout] | ||
(let [base {:run {:name cmd-name | ||
:command cmd}}] | ||
(if no-output-timeout | ||
(assoc-in base [:run :no_output_timeout] no-output-timeout) | ||
base)))) | ||
|
||
(defn make-graalvm-url [arch] | ||
(let [myarch (case arch | ||
"amd64" "x64" | ||
"aarch64" "aarch64")] | ||
(str "https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-" | ||
graalvm-version | ||
"/graalvm-community-jdk-" | ||
graalvm-version | ||
"_linux-" | ||
myarch | ||
"_bin.tar.gz"))) | ||
|
||
(defn build-native-image | ||
[arch resource-class] | ||
(let [cache-key (str arch "-deps-linux-{{ checksum \"deps.edn\" }}") | ||
graalvm-url (make-graalvm-url arch)] | ||
(ordered-map | ||
:machine | ||
{:image "ubuntu-2204:2023.10.1" | ||
:resource_class resource-class} | ||
:working_directory "/home/circleci/replikativ" | ||
:environment {:GRAALVM_VERSION graalvm-version | ||
:DTHK_PLATFORM "linux" | ||
:DTHK_ARCH arch | ||
:PATH "/bin:/home/circleci/graalvm/bin:/home/circleci/clojure/bin:/home/circleci/bin" | ||
:JAVA_HOME "/home/circleci/graalvm/bin/java"} | ||
:steps | ||
[:checkout | ||
{:restore_cache {:keys [cache-key]}} | ||
(run "Install GraalVM" | ||
(format "cd /home/circleci | ||
/bin/wget -O graalvm.tar.gz %s | ||
/bin/mkdir graalvm || true | ||
/bin/tar -xzf graalvm.tar.gz --directory graalvm --strip-components 1 | ||
sudo update-alternatives --install /usr/bin/java java /home/circleci/graalvm/bin/java 0 | ||
sudo update-alternatives --install /usr/bin/javac javac /home/circleci/graalvm/bin/javac 0 | ||
sudo update-alternatives --set java /home/circleci/graalvm/bin/java | ||
sudo update-alternatives --set javac /home/circleci/graalvm/bin/javac" | ||
graalvm-url)) | ||
(run "Install Clojure" | ||
"cd /home/circleci | ||
/bin/curl -sLO https://download.clojure.org/install/linux-install-1.11.1.1165.sh | ||
/bin/chmod +x linux-install-1.11.1.1165.sh | ||
./linux-install-1.11.1.1165.sh --prefix /home/circleci/clojure") | ||
(run "Install Babashka" | ||
"cd /home/circleci | ||
/bin/curl -sLO https://raw.githubusercontent.com/babashka/babashka/master/install | ||
/bin/chmod +x install | ||
./install --dir /home/circleci/bin") | ||
(run "Build native image" | ||
"cd /home/circleci/replikativ | ||
bb ni-cli") | ||
(run "Test native image" | ||
"cd /home/circleci/replikativ | ||
bb test native-image") | ||
{:persist_to_workspace | ||
{:root "/home/circleci/" | ||
:paths ["replikativ/dthk"]}} | ||
{:save_cache | ||
{:paths ["~/.m2" "~/graalvm"] | ||
:key cache-key}}]))) | ||
|
||
(defn release-native-image | ||
[arch] | ||
(let [cache-key (str arch "-deps-linux-{{ checksum \"deps.edn\" }}")] | ||
(ordered-map | ||
:executor "tools/clojurecli" | ||
:working_directory "/home/circleci/replikativ" | ||
:environment {:DTHK_PLATFORM "linux" | ||
:DTHK_ARCH arch} | ||
:steps | ||
[:checkout | ||
{:restore_cache {:keys [cache-key]}} | ||
{:attach_workspace {:at "/home/circleci"}} | ||
(run "Release native image" | ||
"cd /home/circleci/replikativ | ||
bb release native-image") | ||
{:persist_to_workspace | ||
{:root "/home/circleci/" | ||
:paths ["replikativ/dthk"]}} | ||
{:save_cache | ||
{:paths ["~/.m2" "~/graalvm"] | ||
:key cache-key}}]))) | ||
|
||
(defn make-config [] | ||
(ordered-map | ||
:version 2.1 | ||
:orbs | ||
{:tools "replikativ/clj-tools@0"} | ||
:commands | ||
{:setup-docker-buildx | ||
{:steps | ||
[{:run | ||
{:name "Create multi-platform capable buildx builder" | ||
:command | ||
"docker run --privileged --rm tonistiigi/binfmt --install all\ndocker buildx create --name ci-builder --use"}}]}} | ||
:jobs (ordered-map | ||
:build-linux-amd64 (build-native-image "amd64" "large") | ||
:build-linux-aarch64 (build-native-image "aarch64" "arm.large") | ||
:release-linux-amd64 (release-native-image "amd64") | ||
:release-linux-aarch64 (release-native-image "aarch64")) | ||
:workflows (ordered-map | ||
:version 2 | ||
:native-images | ||
{:jobs ["build-linux-amd64" | ||
"build-linux-aarch64" | ||
{"release-linux-amd64" | ||
{:context ["dockerhub-deploy" | ||
"github-token"] | ||
:filters {:branches {:only "main"}} | ||
:requires ["build-linux-amd64"]}} | ||
{"release-linux-aarch64" | ||
{:context ["dockerhub-deploy" | ||
"github-token"] | ||
:filters {:branches {:only "main"}} | ||
:requires ["build-linux-aarch64"]}}]}))) | ||
|
||
(def skip-config | ||
{:skip-if-only [#"^doc\/.*" | ||
#"^bb\/.*" | ||
#"^dev\/.*" | ||
#"^examples\/.*" | ||
#"^test\/.*" | ||
#".*.md$"]}) | ||
|
||
(defn get-changes | ||
[] | ||
(-> (tasks/shell {:out :string} "git diff --name-only HEAD~1") | ||
(:out) | ||
(str/split-lines))) | ||
|
||
(defn irrelevant-change? | ||
[change regexes] | ||
(some? (some #(re-matches % change) regexes))) | ||
|
||
(defn anything-relevant? | ||
[change-set regexes] | ||
(some? (some #(not (irrelevant-change? % regexes)) change-set))) | ||
|
||
(defn main | ||
[] | ||
(let [{:keys [skip-if-only]} skip-config | ||
changed-files (get-changes)] | ||
(when (anything-relevant? changed-files skip-if-only) | ||
(-> (make-config) | ||
(yaml/generate-string :dumper-options {:flow-style :block}) | ||
println)))) | ||
|
||
(when (= *file* (System/getProperty "babashka.file")) | ||
(main)) | ||
|
||
(comment | ||
(def changed-files (get-changes)) | ||
(anything-relevant? changed-files (:skip-if-only skip-config)) | ||
(-> (make-config) | ||
(yaml/generate-string :dumper-options {:flow-style :block}) | ||
println)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
macos_instance: | ||
image: ghcr.io/cirruslabs/macos-monterey-base:latest | ||
|
||
build-task: | ||
env: | ||
DTHK_PLATFORM: macos | ||
DTHK_ARCH: aarch64 | ||
INSTALL_DIR: ${HOME} | ||
GRAALVM_VERSION: 22.0.2 | ||
GRAALVM_SLUG: 9.1 | ||
GRAALVM_HOME: ${HOME}/graalvm-community-openjdk-${GRAALVM_VERSION}+${GRAALVM_SLUG}/Contents/Home/ | ||
GITHUB_TOKEN: ENCRYPTED[0ea782cbbd99c2486b0f55b8eefcf91606a0805faaa3f35e55ecb75268b0046b874c856753f528ba689a9cdaa11e47c2] | ||
script: | | ||
set -euo pipefail | ||
# install babashka | ||
curl -sLO https://raw.githubusercontent.com/babashka/babashka/master/install | ||
chmod +x install | ||
./install --dir ${HOME}/.local/bin | ||
export PATH=${HOME}/.local/bin:$PATH | ||
# install clojure | ||
curl -L -O https://github.com/clojure/brew-install/releases/latest/download/posix-install.sh | ||
chmod +x posix-install.sh | ||
sudo ./posix-install.sh | ||
# install graalvm | ||
pushd "$INSTALL_DIR" >/dev/null | ||
curl -L -O https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-${GRAALVM_VERSION}/graalvm-community-jdk-${GRAALVM_VERSION}_${DTHK_PLATFORM}-${DTHK_ARCH}_bin.tar.gz | ||
sudo xattr -r -d com.apple.quarantine graalvm-community-jdk-${GRAALVM_VERSION}_${DTHK_PLATFORM}-${DTHK_ARCH}_bin.tar.gz | ||
tar -xzf graalvm-community-jdk-${GRAALVM_VERSION}_${DTHK_PLATFORM}-${DTHK_ARCH}_bin.tar.gz | ||
popd >/dev/null | ||
# prepare | ||
export PATH=${GRAALVM_HOME}/bin:${PATH} | ||
export JAVA_HOME=${GRAALVM_HOME} | ||
sudo /usr/sbin/softwareupdate --install-rosetta --agree-to-license | ||
java -version | ||
${GRAALVM_HOME}bin/native-image --version | ||
echo $PATH | ||
native-image --version | ||
# compile | ||
bb ni-cli | ||
# test | ||
file dthk | ||
bb test native-image | ||
bb test bb-pod | ||
# upload artifact | ||
if [[ $CIRRUS_RELEASE == "" ]]; then | ||
bb release native-cli | ||
fi | ||
binaries_artifacts: | ||
path: "dist/*" |
Oops, something went wrong.