Skip to content

Commit

Permalink
Create image and attempt CI
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinlfer committed Apr 23, 2022
1 parent 69895e5 commit 21812a7
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: ci

on:
push:
branches:
- 'main'

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v2
with:
platforms: linux/amd64,linux/arm64
push: true
tags: rubixcubin/scala-graal-builder:latest
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM debian:11-slim

# Artifact information
ARG sdkmanGraalJavaVersion="22.0.0.2.r17-grl"

# User information
ARG username="builder"
ARG useruid=1000
ARG groupid=1000
ARG groupname="buildergroup"
ARG home="/home/$username"

SHELL ["/bin/bash", "-c"]

# Add a non-root user and specify dependencies needed for SDKMAN and GraalVM native image
RUN groupadd -g $groupid $username && \
useradd -m -g $groupid -u $useruid $username && \
apt-get update && \
apt-get install -y curl zip build-essential libz-dev zlib1g-dev

# Switch to the user
USER $useruid:$groupid

# Install SDKMAN
RUN curl -s "https://get.sdkman.io" | bash && \
source $home/.sdkman/bin/sdkman-init.sh && \
sdk install java $sdkmanGraalJavaVersion && \
sdk install sbt && \
gu install native-image
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# A Docker image to build Scala & Graal Native Image projects

This image relies on SDKMAN to provide the following:
* The latest version of SBT at the time of building
* A GraalVM CE flavour of the JVM (currently `22.0.0.2.r17`)
* Graal Native Image to build native image binaries.


## Building locally

1. `docker build -t rubixcubin/scala-graal-builder:local .`
2. `docker run -it rubixcubin/scala-graal-builder:local bash`


## Recommended usage
You can use a multi-stage build if you want to use this image to build your project
and leverage the artifacts produced by the build in a smaller image to package and serve your application.

For example, for a native-image build:
```Dockerfile
# Step 1: Use this image to build your project
FROM rubixcubin/scala-graal-builder:latest as builder
COPY . /build
WORKDIR /build

# This generates the binary that represents your application
RUN sbt graalvm-native-image:packageBin

# This is what you want to use to package and run your application
FROM gcr.io/distroless/base
COPY --from=builder /build/your-project/target/graalvm-native-image /app
CMD ["/app/your-app"]
```

0 comments on commit 21812a7

Please sign in to comment.