Skip to content
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

feat(docker): add spin cli Dockerfiles; add build/push to release.yml #2700

Merged
merged 1 commit into from
Aug 20, 2024
Merged
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
11 changes: 11 additions & 0 deletions .github/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
git

ARG TARGETARCH
ARG TARGETOS
COPY spin-${TARGETOS}-${TARGETARCH} /usr/local/bin/spin

ENTRYPOINT [ "/usr/local/bin/spin" ]
7 changes: 7 additions & 0 deletions .github/distroless.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM gcr.io/distroless/static-debian12

ARG TARGETARCH
ARG TARGETOS
COPY spin-static-${TARGETOS}-${TARGETARCH} /usr/local/bin/spin

ENTRYPOINT [ "/usr/local/bin/spin" ]
77 changes: 77 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,80 @@ jobs:
repository: fermyon/homebrew-tap
event-type: spin-release
client-payload: '{"version": "${{ github.ref_name }}"}'

docker:
runs-on: "ubuntu-20.04"
Copy link
Contributor

Choose a reason for hiding this comment

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

possibly use 22.04?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I propose relegating to a follow-up; this is the version used elsewhere in the workflow so it might be nice to update all at the same time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes 👍🏻 that makes sense. Thank you

needs: [build-and-sign, build-spin-static]
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
strategy:
matrix:
config:
- { dockerfile: "Dockerfile", tag-suffix: "" }
- { dockerfile: "distroless.Dockerfile", tag-suffix: "-distroless" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @vdice, just a curious question: does distroless means static implicitly?

Copy link
Contributor Author

@vdice vdice Aug 14, 2024

Choose a reason for hiding this comment

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

@rajatjindal Yes; well both. It uses a distroless base image and includes the static Spin binary. Open to alternative names... what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if it is worth adding static to the name, if distroless implies static by default, then we can omit it. But otherwise it would be nice to call it out explicitly.

Copy link
Contributor Author

@vdice vdice Aug 15, 2024

Choose a reason for hiding this comment

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

Indeed, I do think distroless implies static by default.

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup version info
id: version
run: |
if [[ "${{ startsWith(github.ref, 'refs/tags/v') }}" == "true" ]]; then
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
else
echo "version=canary" >> $GITHUB_OUTPUT
fi
- name: download release assets
uses: actions/download-artifact@v3
with:
name: spin

- name: extract binaries
shell: bash
run: |
if [[ "${{ matrix.config.tag-suffix }}" == "-distroless" ]]; then
static="-static"
fi
tar xvf spin-${{ steps.version.outputs.version }}${static}-linux-amd64.tar.gz
mv spin spin${static}-linux-amd64
tar xvf spin-${{ steps.version.outputs.version }}${static}-linux-aarch64.tar.gz
# Note: here we s/aarch64/arm64 to conform to Docker's TARGETARCH standards
mv spin spin${static}-linux-arm64
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

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

- name: Build and Push
uses: docker/build-push-action@v6
with:
context: .
file: .github/${{ matrix.config.dockerfile }}
push: true
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}${{ matrix.config.tag-suffix }}
Loading