Skip to content

Commit

Permalink
Merge pull request #2 from kaweezle/feature/base-image-fix
Browse files Browse the repository at this point in the history
✨ Base for building subsequent images
  • Loading branch information
antoinemartin authored Feb 15, 2023
2 parents 3666adb + 3f4eff4 commit 1ab0dd4
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 10 deletions.
42 changes: 32 additions & 10 deletions .github/workflows/base.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# cSpell: disable
name: Publish docker image on docker hub
name: Build base image and RootFS
on:
workflow_dispatch:
push:
branches:
- "master"
- "main"
tags:
- "v*"
pull_request:
branches:
- "master"
- "main"

jobs:
publish:
build-base:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -52,25 +52,47 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=tar,dest=alpine-boxes-base.tar
outputs: type=tar,dest=alpine-boxes-base.rootfs.tar

- name: Compress root filesystem and compute checksum
run: |
gzip alpine-boxes-base.tar
sha256sum alpine-boxes-base.tar.gz >> SHA256SUMS
gzip alpine-boxes-base.rootfs.tar
sha256sum alpine-boxes-base.rootfs.tar.gz >> SHA256SUMS
- name: Upload root fs artifact
uses: actions/upload-artifact@v3
with:
name: rootfs
path: |
alpine-boxes-base.tar.gz
alpine-boxes-base.rootfs.tar.gz
- name: Upload shasums artifact
uses: actions/upload-artifact@v3
with:
name: shasums
path: |
SHA256SUMS
build-docker:
needs: [build-base]
uses: ./.github/workflows/build-box.yml
with:
context: docker
secrets: inherit

release-rootfses:
needs: [build-base, build-docker]
runs-on: ubuntu-latest
if: contains(github.ref, 'refs/tags/v') && !github.event.release.prerelease
steps:
- name: Get Root File Systems
uses: actions/download-artifact@v3

- name: release
if: contains(github.ref, 'refs/tags/v') && !github.event.release.prerelease
uses: softprops/action-gh-release@v1
with:
files: |
alpine-boxes-base.tar.gz
alpine-boxes-*.rootfs.tar.gz
SHA256SUMS
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84 changes: 84 additions & 0 deletions .github/workflows/build-box.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# cSpell: disable
name: Build a box
on:
workflow_call:
inputs:
context:
required: true
type: string
# secrets:
# token:
# required: true

jobs:
build-base:
runs-on: ubuntu-latest
outputs:
sha256sum: ${{ steps.compress.outputs.sha256sum }}
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: |
image=moby/buildkit:master
- name: Docker Login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}-${{ inputs.context }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: ${{ inputs.context }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Export as root fs
uses: docker/build-push-action@v3
with:
context: ${{ inputs.context }}
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=tar,dest=alpine-boxes-${{ inputs.context }}.rootfs.tar

- name: Get distributions
uses: actions/download-artifact@v3
with:
name: shasums

- name: Compress root filesystem and compute checksum
id: compress
env:
BOX_NAME: ${{ inputs.context }}
run: |
gzip alpine-boxes-${BOX_NAME}.rootfs.tar
sha256sum alpine-boxes-${BOX_NAME}.rootfs.tar.gz >> SHA256SUMS
echo "sha256sum=$(tail -1 SHA256SUMS)" >>$GITHUB_OUTPUT
- name: Upload root fs artifact
uses: actions/upload-artifact@v3
with:
name: rootfs
path: |
alpine-boxes-${{ inputs.context }}.rootfs.tar.gz
- name: shasums artifact
uses: actions/upload-artifact@v3
with:
name: shasums
path: |
SHA256SUMS
10 changes: 10 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ARG BASE_VERSION=latest

FROM ghcr.io/kaweezle/alpine-boxes-base:${BASE_VERSION}

USER root

RUN apk add --no-cache docker && \
rc-update add docker default

USER alpine

0 comments on commit 1ab0dd4

Please sign in to comment.