Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
./out
.bloop
.bsp
.metals
.scala-build
.scala
gifs
website
.github
Dockerfile
133 changes: 133 additions & 0 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Create and publish a Docker image

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# Configures this workflow to run every time a change is pushed to the branch called `release`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...you mean like, v* tags and main, right?

on:
push:
branches: ["main"]
tags: ["v*"]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
DOCKERFILE: ./Dockerfile
REGISTRY_LOGIN: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

jobs:
docker_build:
strategy:
fail-fast: true
matrix:
os: ["ubuntu-22.04", "ubuntu-22.04-arm"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
os: ["ubuntu-22.04", "ubuntu-22.04-arm"]
os: ["ubuntu-24.04", "ubuntu-24.04-arm"]

we're using 24.04 everywhere in the build, I think

runs-on: ${{ matrix.os }}
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a version from two years ago, shouldn't we bump it up to the latest one?

with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
Comment on lines +42 to +43

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
username: ${{ env.REGISTRY_LOGIN }}
password: ${{ env.REGISTRY_PASSWORD }}


# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same situation, a very old version.

with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same situation, a very old version.

with:
context: .
file: ${{ env.DOCKERFILE }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.os }}
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.os }},mode=max
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attest-build-provenance documentation says to use version @v3

with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.push.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.os }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

docker_release_merge:
runs-on: ubuntu-22.04
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

permissions:
contents: read
packages: write
attestations: write
id-token: write
needs: [docker_build]
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
pattern: digests-*
path: /tmp/digests
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
Comment on lines +116 to +117

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
username: ${{ env.REGISTRY_LOGIN }}
password: ${{ env.REGISTRY_PASSWORD }}


- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM eclipse-temurin:17 as build
RUN apt update && apt install build-essential libz-dev clang procps git -y
WORKDIR /workdir
COPY . .
RUN ./mill -i copyTo --task 'cli[].base-image.nativeImage' --dest "./docker-out/scala-cli" 1>&2

FROM debian:stable-slim
RUN apt update && apt install build-essential libz-dev clang procps -y
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I'm not sure if installing those dependencies in a base image is a good idea, or better left to downstream images. Even though I see the appeal of making native and native-image stuff work out of the box..

Main concern is the size
CleanShot 2025-11-19 at 09 38 47@2x

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, we definitely want Scala Native to build nicely with it, so clang is a must.
I'd like to keep them, I think.

COPY --from=build /workdir/docker-out/scala-cli /usr/bin/scala-cli
RUN \
echo "println(1)" | scala-cli -S 3 - -v -v -v && \
echo "println(1)" | scala-cli -S 2.13 - -v -v -v && \
echo "println(1)" | scala-cli -S 2.12 - -v -v -v
RUN \
echo "println(1)" | scala-cli --power package --native _.sc --force && \
echo "println(1)" | scala-cli --power package --native-image _.sc --force

ENTRYPOINT ["scala-cli"]