Skip to content

Commit

Permalink
PIP-5 PIP-6 PIP-7 #done add cli compilation and dockerfile (#24)
Browse files Browse the repository at this point in the history
* PIP-5 PIP-7 add cli compilation and dockerfile

* trim modules

* duplicated LRSQLs runtime strategy

* single place to list modules, currently pegged to runtimer

* PIP-7 slimmer docker

* minimize docker java modules

* PIP-7 ability to build + draft release

* dont be so cavalier about unzipping I guess

* forgot the -d

* individual again

* move the runtimes to the right places

* add docker release
  • Loading branch information
milt authored Nov 9, 2021
1 parent 55f4f32 commit 9e09324
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# exclude runtimes as we build our own on alpine
/target/bundle/runtimes
90 changes: 90 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ pom.xml.asc
failures/
/store/
/.test_store/
/tmp/
1 change: 1 addition & 0 deletions .java_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java.base,java.logging,java.naming,java.sql
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
57 changes: 56 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions bin/machine.sh
Original file line number Diff line number Diff line change
@@ -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}
5 changes: 5 additions & 0 deletions bin/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

MACHINE=`bin/machine.sh`

runtimes/$MACHINE/bin/java -server -jar xapipe.jar $@
7 changes: 4 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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]}}}}

0 comments on commit 9e09324

Please sign in to comment.