-
Notifications
You must be signed in to change notification settings - Fork 149
Self-contained docker build with ARM64 publishing #3962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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`. | ||||||||||
| 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"] | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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 | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| # 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 | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||||||
| 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 | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| 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 | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| - 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 }} | ||||||||||
| 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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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"] | ||

There was a problem hiding this comment.
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 andmain, right?