-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from mutablelogic/v1
Added container workflow
- Loading branch information
Showing
5 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
name: Build docker container | ||
on: | ||
release: | ||
types: [ created, edited ] | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: 'tag' | ||
required: true | ||
default: 'latest' | ||
type: string | ||
jobs: | ||
var: | ||
name: Set variables | ||
runs-on: ubuntu-latest | ||
outputs: | ||
platform: "linux" | ||
image: "ghcr.io/${{ github.repository }}" | ||
tag: ${{ steps.var.outputs.tag }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set variables | ||
id: var | ||
run: | | ||
if [ "${{ github.event_name }}" != "release" ] && [ "${{ inputs.tag }}" != "latest" ]; then | ||
TAG="${{ inputs.tag }}" && echo "tag=${TAG#v}" >> $GITHUB_OUTPUT | ||
else | ||
TAG="$(git describe --tags)" && echo "tag=${TAG#v}" >> $GITHUB_OUTPUT | ||
fi | ||
build: | ||
name: Build | ||
needs: var | ||
strategy: | ||
matrix: | ||
arch: [ amd64, arm64 ] | ||
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || matrix.arch }} | ||
steps: | ||
- name: Install git | ||
run: | | ||
sudo apt -y update | ||
sudo apt -y install build-essential git | ||
git config --global advice.detachedHead false | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Login | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build | ||
run: | | ||
git checkout v${{ needs.var.outputs.tag }} | ||
make docker | ||
- name: Push | ||
run: | | ||
docker image tag \ | ||
go-client-${{ needs.var.outputs.platform }}-${{ matrix.arch }}:${{ needs.var.outputs.tag }} \ | ||
${{ needs.var.outputs.image }}-${{ matrix.arch }}:${{ needs.var.outputs.tag }} | ||
docker push ${{ needs.var.outputs.image }}-${{ matrix.arch }}:${{ needs.var.outputs.tag }} | ||
manifest: | ||
name: Manifest | ||
needs: | ||
- var | ||
- build | ||
strategy: | ||
matrix: | ||
include: | ||
- tag: ${{ needs.var.outputs.tag }} | ||
- tag: latest | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Login | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Create Manifest | ||
run: | | ||
docker manifest create ${{ needs.var.outputs.image }}:${{ matrix.tag }} \ | ||
--amend ${{ needs.var.outputs.image }}-amd64:${{ needs.var.outputs.tag }} \ | ||
--amend ${{ needs.var.outputs.image }}-arm64:${{ needs.var.outputs.tag }} | ||
docker manifest annotate --arch arm64 \ | ||
${{ needs.var.outputs.image }}:${{ matrix.tag }} \ | ||
${{ needs.var.outputs.image }}-arm64:${{ needs.var.outputs.tag }} | ||
docker manifest annotate --arch amd64 \ | ||
${{ needs.var.outputs.image }}:${{ matrix.tag }} \ | ||
${{ needs.var.outputs.image }}-amd64:${{ needs.var.outputs.tag }} | ||
docker manifest push ${{ needs.var.outputs.image }}:${{ matrix.tag }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
build | ||
etc/_cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
ARG OS | ||
ARG ARCH | ||
|
||
# Run makefile to build all the commands | ||
FROM --platform=${OS}/${ARCH} golang:1.21-bullseye AS builder | ||
ARG OS | ||
ARG ARCH | ||
WORKDIR /usr/src/app | ||
COPY . . | ||
RUN OS=${OS} ARCH=${ARCH} make | ||
|
||
# Copy server to /usr/local/bin | ||
FROM --platform=${OS}/${ARCH} debian:bullseye-slim | ||
ARG OS | ||
ARG ARCH | ||
ARG SOURCE | ||
RUN apt update && apt install -y ca-certificates | ||
COPY --from=builder /usr/src/app/build/* /usr/local/bin/ | ||
COPY etc/entrypoint.sh . | ||
|
||
# Labels | ||
LABEL org.opencontainers.image.source=${SOURCE} | ||
|
||
# Entrypoint when running the server | ||
ENTRYPOINT [ "/entrypoint.sh" ] | ||
CMD [ "/usr/local/bin/api" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
if [ -z "$1" ]; then | ||
echo "No command specified" | ||
exit 1 | ||
fi | ||
|
||
# Nomad: Create the /alloc/logs folder if it doesn't exist | ||
install -d -m 0755 /alloc/logs || exit 1 | ||
|
||
# Run the command | ||
set -e | ||
exec "$@" |