diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..a3bbeb2f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +# exclude runtimes as we build our own on alpine +/target/bundle/runtimes diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..3c3a0d0a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,90 @@ +name: Release + +# Draft Release on any tag +on: + push: + tags: + - '*' + +jobs: + build_jre: + uses: yetanalytics/runtimer/.github/workflows/runtimer.yml@cf8c77d465f08962cd7901005b8cf197a6149ac1 + with: + java-version: '11' + java-distribution: 'temurin' + java-modules: 'java.base,java.logging,java.naming,java.sql' + + build: + needs: build_jre + runs-on: ubuntu-latest + steps: + - name: Get an env + uses: yetanalytics/actions/setup-env@v0 + + - name: Cache Deps + uses: actions/cache@v2 + with: + path: | + ~/.m2 + ~/.gitlibs + key: ${{ runner.os }}-deps-${{ hashFiles('deps.edn') }} + restore-keys: | + ${{ runner.os }}-cljdeps- + - name: Build Xapipe + run: make bundle BUNDLE_RUNTIMES=false + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_CI_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: yetanalytics/xapipe + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + + - name: Download ubuntu-latest Artifact + uses: actions/download-artifact@v2 + with: + name: ubuntu-20.04-jre + + - name: Download macOS-latest Artifact + uses: actions/download-artifact@v2 + with: + name: macos-10.15-jre + + - name: Download windows-latest Artifact + uses: actions/download-artifact@v2 + with: + name: windows-2019-jre + + - name: Unzip the runtimes + run: | + mkdir -p target/bundle/runtimes + unzip ubuntu-20.04-jre.zip -d target/bundle/runtimes + mv target/bundle/runtimes/ubuntu-20.04 target/bundle/runtimes/linux + unzip macos-10.15-jre.zip -d target/bundle/runtimes + mv target/bundle/runtimes/macos-10.15 target/bundle/runtimes/macos + unzip windows-2019-jre.zip -d target/bundle/runtimes + mv target/bundle/runtimes/windows-2019 target/bundle/runtimes/windows + + - name: Zip the bundle + run: | + cd target/bundle + zip -r ../../xapipe.zip ./ + + - name: Craft Draft Release + uses: softprops/action-gh-release@v1 + with: + body: "## Release Notes\nTODO: Create great release notes!" + draft: true + files: 'xapipe.zip' diff --git a/.gitignore b/.gitignore index 7a42cd03..cd46bf95 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ pom.xml.asc failures/ /store/ /.test_store/ +/tmp/ diff --git a/.java_modules b/.java_modules new file mode 100644 index 00000000..abbcc912 --- /dev/null +++ b/.java_modules @@ -0,0 +1 @@ +java.base,java.logging,java.naming,java.sql diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..df5d6c60 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM alpine:3.14 + +ADD target/bundle /xapipe +ADD .java_modules /xapipe/.java_modules + +# replace the linux runtime via jlink +RUN apk update \ + && apk upgrade \ + && apk add ca-certificates \ + && update-ca-certificates \ + && apk add --no-cache openjdk11 \ + && mkdir -p /xapipe/runtimes \ + && jlink --output /xapipe/runtimes/linux/ --add-modules $(cat /xapipe/.java_modules) \ + && apk del openjdk11 \ + && rm -rf /var/cache/apk/* + +WORKDIR /xapipe +ENTRYPOINT ["/xapipe/bin/run.sh"] +CMD ["--help"] diff --git a/Makefile b/Makefile index a5251c59..17c55efe 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,62 @@ -.phony: test-lib bench +.phony: test-lib bench clean bundle + +clean: + rm -rf target classes test-lib: clojure -X:cli:test :dirs '["src/test"]' bench: clojure -Xtest:bench + +target/bundle/xapipe.jar: + mkdir -p target/bundle + clojure -Xuberjar + +target/bundle/bin: + mkdir -p target/bundle/bin + cp bin/*.sh target/bundle/bin + chmod +x target/bundle/bin/*.sh + +# Make Runtime Environment (i.e. JREs) + +# The given tag to pull down from yetanalytics/runtimer release +RUNTIME_TAG ?= 0.1.1-java-11-temurin +RUNTIME_MACHINE ?= macos +RUNTIME_MACHINE_BUILD ?= macos-10.15 +RUNTIME_ZIP_DIR ?= tmp/runtimes/${RUNTIME_TAG} +RUNTIME_ZIP ?= ${RUNTIME_ZIP_DIR}/${RUNTIME_MACHINE}.zip +JAVA_MODULES ?= $(shell cat .java_modules) + +# DEBUG: Kept here for reference +# target/bundle/runtimes: target/bundle/bin +# mkdir target/bundle/runtimes +# jlink --output target/bundle/runtimes/$(MACHINE_TYPE) --add-modules $(JAVA_MODULES) + +target/bundle/runtimes/%: + mkdir -p ${RUNTIME_ZIP_DIR} + mkdir -p target/bundle/runtimes + [ ! -f ${RUNTIME_ZIP} ] && curl -L -o ${RUNTIME_ZIP} https://github.com/yetanalytics/runtimer/releases/download/${RUNTIME_TAG}/${RUNTIME_MACHINE_BUILD}-jre.zip || echo 'already present' + unzip ${RUNTIME_ZIP} -d target/bundle/runtimes/ + mv target/bundle/runtimes/${RUNTIME_MACHINE_BUILD} target/bundle/runtimes/${RUNTIME_MACHINE} + +target/bundle/runtimes/macos: RUNTIME_MACHINE = macos +target/bundle/runtimes/macos: RUNTIME_MACHINE_BUILD = macos-10.15 + +target/bundle/runtimes/linux: RUNTIME_MACHINE = linux +target/bundle/runtimes/linux: RUNTIME_MACHINE_BUILD = ubuntu-20.04 + +target/bundle/runtimes/windows: RUNTIME_MACHINE = windows +target/bundle/runtimes/windows: RUNTIME_MACHINE_BUILD = windows-2019 + +target/bundle/runtimes: target/bundle/runtimes/macos target/bundle/runtimes/linux target/bundle/runtimes/windows + +BUNDLE_RUNTIMES ?= true + +ifeq ($(BUNDLE_RUNTIMES),true) +target/bundle: target/bundle/xapipe.jar target/bundle/bin target/bundle/runtimes +else +target/bundle: target/bundle/xapipe.jar target/bundle/bin +endif + +bundle: target/bundle diff --git a/bin/machine.sh b/bin/machine.sh new file mode 100755 index 00000000..40b203ea --- /dev/null +++ b/bin/machine.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +#TODO: Add windows, possibly better macos targeting + +unameOut="$(uname -s)" +case "${unameOut}" in + Linux*) machine=linux;; + *) machine=macos;; +esac + +echo ${machine} diff --git a/bin/run.sh b/bin/run.sh new file mode 100755 index 00000000..46e932d4 --- /dev/null +++ b/bin/run.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +MACHINE=`bin/machine.sh` + +runtimes/$MACHINE/bin/java -server -jar xapipe.jar $@ diff --git a/deps.edn b/deps.edn index 4d9d2395..90146fd9 100644 --- a/deps.edn +++ b/deps.edn @@ -46,6 +46,7 @@ :uberjar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.278"}} :exec-fn hf.depstar/uberjar :exec-args {:aot true - :jar "xapipe.jar" - :main-class "com.yetanalytics.xapipe" - :sync-pom true}}}} + :jar "target/bundle/xapipe.jar" + :main-class "com.yetanalytics.xapipe.main" + :sync-pom true + :aliases [:cli]}}}}