Skip to content

Commit

Permalink
build: switch to buildah
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogyuchi committed Aug 23, 2024
1 parent 59accc7 commit ce05c54
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 42 deletions.
14 changes: 0 additions & 14 deletions .github/files/build/Dockerfile

This file was deleted.

52 changes: 28 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ on:
type: string
outputs:
image_tags:
value: ${{ jobs.docker.outputs.image_tags }}
value: ${{ jobs.image.outputs.image_tags }}
image_url:
value: https://ghcr.io/${{ github.repository }}

env:
# const
REGISTRY: ghcr.io
IMAGE_REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
BINARY_NAME: ${{ github.event.repository.name }}
# env
Expand Down Expand Up @@ -88,22 +88,15 @@ jobs:
mv binary "$filename"
gh release upload ${{ inputs.tag-name }} "$filename"#${{ matrix.target }} --clobber
fi
docker:
image:
needs: build
if: ${{ github.event_name != 'pull_request' }}
permissions:
packages: write
runs-on: "ubuntu-latest"
outputs:
image_tags: ${{ steps.meta.outputs.tags }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
sparse-checkout: |
.github/files/build/Dockerfile
sparse-checkout-cone-mode: false
- name: Download build artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
Expand All @@ -114,29 +107,40 @@ jobs:
- name: Log in to the Container registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ env.REGISTRY }}
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}},value=${{ inputs.tag-name }}
type=semver,pattern={{major}}.{{minor}},value=${{ inputs.tag-name }}
type=semver,pattern={{major}},value=${{ inputs.tag-name }},enable=${{ !(startsWith(github.ref, 'refs/tags/v0.') || startsWith(inputs.tag-name, 'v0.')) }}
type=edge
type=ref,event=branch
- name: Build and push Docker image
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0
with:
context: .
file: .github/files/build/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build Images
run: |
build() {
newcontainer=$(buildah from --platform="$1" scratch)
buildah copy --chmod=0755 $newcontainer ./artifact/"$2"/binary /binary
buildah config --entrypoint='["./binary"]' $newcontainer
buildah config --author="Mogyuchi" $(awk '{print "--label=" $0}' <<< "${{ steps.meta.outputs.labels }}") $newcontainer
buildah inspect $newcontainer
buildah commit --manifest=localhost/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} $newcontainer
buildah rm $newcontainer
}
build linux/amd64 x86_64-unknown-linux-musl
build linux/arm64 aarch64-unknown-linux-musl
- id: push
name: Push To GHCR
run: |
buildah manifest inspect localhost/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
tac <<< '${{ steps.meta.outputs.tags }}' | xargs -I{} --max-args=1 buildah manifest push --creds=${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} --all localhost/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} docker://{}
8 changes: 4 additions & 4 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
manifest-file: .github/files/release-please/.release-please-manifest.json
skip-github-pull-request: ${{ startsWith(github.event.head_commit.message, 'release:') && github.event.head_commit.author.name == format('{0}[bot]', steps.generate_token.outputs.app-slug) }}

docker-publish:
image-publish:
needs: release-please
if: ${{ needs.release-please.outputs.release_created }}
permissions:
Expand All @@ -41,7 +41,7 @@ jobs:
tag-name: ${{ needs.release-please.outputs.tag_name }}

publish-release:
needs: [release-please, docker-publish]
needs: [release-please, image-publish]
if: ${{ needs.release-please.outputs.release_created }}
permissions:
contents: write
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
edit-mode: replace

add-docker-comment:
needs: [release-please, docker-publish, get-pr-number]
needs: [release-please, image-publish, get-pr-number]
if: ${{ needs.release-please.outputs.release_created }}
permissions:
pull-requests: write
Expand All @@ -102,7 +102,7 @@ jobs:
steps:
- name: Add comment to PR
run: |
printf ':robot: Successfully published to ${{ needs.docker-publish.outputs.image_url }} :truck:\n```\n${{ join(needs.docker-publish.outputs.image_tags, '\n') }}\n```' \
printf ':robot: Successfully published to ${{ needs.image-publish.outputs.image_url }} :truck:\n```\n${{ join(needs.image-publish.outputs.image_tags, '\n') }}\n```' \
| gh pr comment ${{ needs.get-pr-number.outputs.pr_number }} --body-file=-
label-published:
Expand Down

0 comments on commit ce05c54

Please sign in to comment.