Skip to content

Commit

Permalink
Merge pull request #30 from ZettaScaleLabs/feat-release-crates-docker…
Browse files Browse the repository at this point in the history
…hub-and-ghcr

feat: Add release-crartes-dockerhub/ghcr workflows
  • Loading branch information
J-Loudet authored Mar 12, 2024
2 parents 9e6f9b6 + eb0eddb commit 461c4a5
Show file tree
Hide file tree
Showing 5 changed files with 351 additions and 0 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/release-crates-dockerhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Release crates (DockerHub)

on:
workflow_call:
inputs:
live-run:
type: string
required: false
repo:
type: string
required: true
version:
type: string
required: true
branch:
type: string
required: false
binary:
type: string
required: true
files:
type: string
required: true
platforms:
type: string
required: true
tags:
type: string
required: true
licenses:
type: string
required: false
no-build:
type: boolean
required: false
default: false
workflow_dispatch:
inputs:
live-run:
type: string
required: false
repo:
type: string
required: true
version:
type: string
required: true
branch:
type: string
required: false
binary:
type: string
required: true
files:
type: string
required: true
platforms:
type: string
required: true
tags:
type: string
required: true
licenses:
type: string
required: false
no-build:
type: boolean
required: false
default: false

jobs:
build:
if: ${{ !inputs.no-build }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [x86_64-unknown-linux-musl, aarch64-unknown-linux-musl]
steps:
- uses: eclipse-zenoh/ci/build-crates-standalone@main
with:
repo: ${{ inputs.repo }}
version: ${{ inputs.version }}
branch: ${{ inputs.branch }}
target: ${{ matrix.target }}
artifact-patterns: ${{ inputs.files }}
github-token: ${{ secrets.BOT_WORKFLOW_TOKEN }}

publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: eclipse-zenoh/ci/publish-crates-docker@main
with:
repo: ${{ inputs.repo }}
version: ${{ inputs.version }}
live-run: ${{ inputs.live-run }}
files: ${{ inputs.files }}
binary: ${{ inputs.binary }}
platforms: ${{ inputs.platforms }}
tags: ${{ inputs.tags }}
licenses: ${{ inputs.licenses }}
username: ${{ secrets.DOCKER_COM_USERNAME }}
password: ${{ secrets.DOCKER_COM_PASSWORD }}
105 changes: 105 additions & 0 deletions .github/workflows/release-crates-ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Release crates (GHCR)

on:
workflow_call:
inputs:
live-run:
type: string
required: false
repo:
type: string
required: true
version:
type: string
required: true
branch:
type: string
required: false
binary:
type: string
required: true
files:
type: string
required: true
platforms:
type: string
required: true
tags:
type: string
required: true
licenses:
type: string
required: false
no-build:
type: boolean
required: false
default: false
workflow_dispatch:
inputs:
live-run:
type: string
required: false
repo:
type: string
required: true
version:
type: string
required: true
branch:
type: string
required: false
binary:
type: string
required: true
files:
type: string
required: true
platforms:
type: string
required: true
tags:
type: string
required: true
licenses:
type: string
required: false
no-build:
type: boolean
required: false
default: false

jobs:
build:
if: ${{ !inputs.no-build }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [x86_64-unknown-linux-musl, aarch64-unknown-linux-musl]
steps:
- uses: eclipse-zenoh/ci/build-crates-standalone@main
with:
repo: ${{ inputs.repo }}
version: ${{ inputs.version }}
branch: ${{ inputs.branch }}
target: ${{ matrix.target }}
artifact-patterns: ${{ inputs.files }}
github-token: ${{ secrets.BOT_WORKFLOW_TOKEN }}

publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: eclipse-zenoh/ci/publish-crates-docker@main
with:
repo: ${{ inputs.repo }}
version: ${{ inputs.version }}
live-run: ${{ inputs.live-run }}
files: ${{ inputs.files }}
registry: ghcr.io
binary: ${{ inputs.binary }}
platforms: ${{ inputs.platforms }}
tags: ${{ inputs.tags }}
licenses: ${{ inputs.licenses }}
username: eclipse-zenoh-bot
password: ${{ secrets.BOT_WORKFLOW_TOKEN }}
23 changes: 23 additions & 0 deletions publish-crates-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM alpine:latest

ARG TARGETPLATFORM
ARG BINARY

RUN apk add --no-cache libgcc libstdc++

COPY $TARGETPLATFORM/* /
ENV BINARY $BINARY

RUN echo '#!/bin/ash' > /entrypoint.sh
RUN echo 'cat /entrypoint.sh' >> /entrypoint.sh
RUN echo 'echo " * Starting: /$BINARY $*"' >> /entrypoint.sh
RUN echo 'exec /$BINARY $*' >> /entrypoint.sh
RUN chmod +x /entrypoint.sh

EXPOSE 7446/udp
EXPOSE 7447/tcp
EXPOSE 8000/tcp

ENV RUST_LOG info

ENTRYPOINT ["/entrypoint.sh"]
79 changes: 79 additions & 0 deletions publish-crates-docker/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Publish crates (Docker)

description: Publish crates to a Docker registry

inputs:
repo:
description: Target GitHub repository
required: true
version:
description: Release tag
required: true
live-run:
description: Whether or not to push the image to the registry
required: false
binary:
description: Name of the executable used as an entrypoint
required: true
files:
description: Files to be copied into the image
required: true
tags:
description: List of Docker tags
required: true
licenses:
description: List of licenses
required: true
platforms:
description: List of target platforms
required: true
registry:
description: Address of Docker registry. Defaults to Docker Hub
required: false
username:
description: Username for authenticating with the registry
required: true
password:
description: Password or token for authenticating with the registry
required: true

runs:
using: composite
steps:
- uses: actions/download-artifact@v4
with:
pattern: '*-standalone.zip'
path: download-path
merge-multiple: true

- run: ls -R
shell: bash

- id: prepare
run: bash ${{ github.action_path }}/prepare.bash
shell: bash
env:
DOWNLOAD_PATH: download-path
REPO: ${{ inputs.repo }}
VERSION: ${{ inputs.version }}
PLATFORMS: ${{ inputs.platforms }}
FILES: ${{ inputs.files }}

- uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.username }}
password: ${{ inputs.password }}

- uses: docker/setup-buildx-action@v3

- uses: docker/build-push-action@v5
with:
context: ${{ steps.prepare.outputs.context }}
file: ${{ github.action_path }}/Dockerfile
platforms: ${{ inputs.platforms }}
push: ${{ inputs.live-run }}
tags: ${{ inputs.tags }}
labels: |
org.opencontainers.image.source=https://github.com/${{ inputs.repo }}
org.opencontainers.image.licenses=${{ inputs.licenses }}
40 changes: 40 additions & 0 deletions publish-crates-docker/prepare.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

readonly DOWNLOAD_PATH
readonly REPO
readonly VERSION
readonly PLATFORMS
readonly FILES

readonly linux_amd64="linux/amd64"
readonly linux_arm64="linux/arm64"
readonly context=$(mktemp -d)

echo "context=$context" >> "$GITHUB_OUTPUT"

function prepare() {
local platform="$1"
local target="$2"

local tmp=$(mktemp -d)
unzip "$DOWNLOAD_PATH/${REPO#*/}-$VERSION-$target-standalone.zip" -d "$tmp"

local output="$context/$platform"
mkdir -p "$output"
for file in $FILES; do cp "$tmp/$file" "$output"; done
}

for platform in $PLATFORMS; do
case "$platform" in
"$linux_amd64")
prepare "$linux_amd64" "x86_64-unknown-linux-musl"
;;
"$linux_arm64")
prepare "$linux_arm64" "aarch64-unknown-linux-musl"
;;
*)
echo "error: Unsupported Docker platform specifier $platform"
exit 1
;;
esac
done

0 comments on commit 461c4a5

Please sign in to comment.