Skip to content

Commit

Permalink
initial working
Browse files Browse the repository at this point in the history
  • Loading branch information
q0rban committed Oct 11, 2023
1 parent bb2393a commit 03b0b6f
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: build

on:
pull_request:
types: [opened, reopened, synchronize]
push:
branches:
- main
workflow_dispatch:
inputs:
push:
description: Push to Docker hub after build is complete.
default: true
type: boolean
schedule:
- cron: '0 0 * * 6'

env:
TASK_VERSION: v3.29.1
TASK_CHECKSUM: e411770abf73d5e094100ab7a1c8278f35b591ecadbfd778200b6b2ad1ee340b
PUSH: ${{ (inputs.push || github.event_name == 'schedule' || github.event_name == 'push') && 'true' || 'false' }}

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt-get update
&& sudo apt-get install -y eatmydata
&& sudo ln -snf /usr/bin/eatmydata /usr/local/bin/apt-get
&& sudo apt-get install -y curl
&& curl -L -o /tmp/task_linux_amd64.deb https://github.com/go-task/task/releases/download/${{ env.TASK_VERSION }}/task_linux_amd64.deb
&& sha256sum /tmp/task_linux_amd64.deb | grep -q ${{ env.TASK_CHECKSUM }}
&& sudo dpkg -i /tmp/task_linux_amd64.deb
&& sudo apt-get clean
&& sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
-
# Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
# Expose the actions cache url and token.
# https://github.com/tonistiigi/go-actions-cache/blob/master/api.md#authentication
name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v2
- run: task
id: task
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ARG FROM_TAG

FROM debian:$FROM_TAG

RUN \
sed -e 's/^Components: main$/& contrib/g' -i /etc/apt/sources.list.d/debian.sources && \
apt-get update && \
apt-get install --yes --no-install-recommends zfsutils-linux
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is a very simple docker image starting from Debian slim with just
zfsutils-linux package installed.
85 changes: 85 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: 3

dotenv:
- .env.local
- .local.env
- .env

env:
NAMESPACE: tugboat
IMAGE_NAME: zfs-utils
# Separate each platform with a comma.
PLATFORMS: linux/amd64,linux/arm64
# Separate each tag with a comma.
TAGS: latest,bookworm-slim
FROM_TAG: bookworm-slim

vars:
BUILDX_BUILDER:
sh: echo "{{.NAMESPACE}}-{{.IMAGE_NAME}}"
IMAGE_TAGS:
sh: echo "{{.TAGS}}" | sed -E 's@(^|,)([^,]+)@ --tag {{.NAMESPACE}}/{{.IMAGE_NAME}}:\2@g'

tasks:
default:
desc: 'Builds the image. Set PUSH=1 to push after building.'
cmds:
- task: create-builder
- task: build

create-builder:
desc: '[subtask] Create the Docker buildx builder.'
status:
# Exits zero (up to date) if there is already a builder.
- docker buildx ls | grep -q '^{{.BUILDX_BUILDER}}\s'
cmds:
- docker buildx create
--name "{{.BUILDX_BUILDER}}"
--platform "{{.PLATFORMS}}"
--bootstrap
--use

build:
desc: '[subtask] Build any docker image tarballs generated from bake for Tugboat usage.'
vars:
PUSH_OPT:
sh: (test "$PUSH" != "true" && test "$PUSH" != "1") || echo "--push"
cmds:
- docker buildx use "{{.BUILDX_BUILDER}}"
- echo 'PUSH_OPT {{.PUSH_OPT}}'
- docker buildx build
--build-arg FROM_TAG={{.FROM_TAG}}
--platform "{{.PLATFORMS}}"
{{.IMAGE_TAGS}} {{.PUSH_OPT}} .

clean:
desc: 'Removes all generated files and docker images.'
prompt: This will remove any generated files and delete all docker images in
the {{.NAMESPACE}}/* namespace. Do you want to continue?
deps:
- rm-images

clean-all:
desc: 'Removes the buildkit builder, all generated files, and all docker images.'
deps:
- rm-builder
- rm-images
prompt: This will remove the buildkit builder, all generated files, and
delete all docker images in the {{.NAMESPACE}}/* namespace. Do you
want to continue?

rm-builder:
internal: true
status:
- if docker buildx ls | grep -q '^{{.BUILDX_BUILDER}}\s'; then exit 1; fi
cmd: docker buildx rm -f '{{.BUILDX_BUILDER}}'
rm-images:
internal: true
status:
- test -z "{{.IMAGES}}"
vars:
IMAGES:
sh: docker images ls --filter=reference="{{.NAMESPACE}}/{{.IMAGE_NAME}}" -q | sort | uniq
cmd: docker rmi --force $(echo "{{.IMAGES}}") || true

0 comments on commit 03b0b6f

Please sign in to comment.