Skip to content

Commit

Permalink
feat(): add GitHub actions to build Docker Image
Browse files Browse the repository at this point in the history
  • Loading branch information
e7d committed Mar 28, 2024
1 parent abe7cd4 commit 3f7fbb2
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: docker-image

on:
push:
tags:
- "*"
branches:
- "feat/main/github-actions"

env:
DOCKERHUB_IMAGE: e7db/diskmark
GHCR_IMAGE: ghcr.io/e7d/docker-diskmark

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and export
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
cache-from: type=registry,ref=${{ env.DOCKERHUB_IMAGE }}:buildcache
cache-to: type=registry,ref=${{ env.DOCKERHUB_IMAGE }}:buildcache,mode=max
push: true
tags: ${{ env.DOCKERHUB_IMAGE }}:${{ github.sha }}
outputs: type=docker,dest=/tmp/image.tar

publish:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: image
path: /tmp
- name: Load image
run: |
docker load --input /tmp/image.tar
docker inspect ${{ env.DOCKERHUB_IMAGE }}:${{ github.sha }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push image to Docker Hub
run: |
docker push ${{ env.DOCKERHUB_IMAGE }}:${{ github.sha }}
- name: Push "tag" to Docker Hub
if: github.ref_type == 'tag'
run: |
docker buildx imagetools create \
--tag ${{ env.DOCKERHUB_IMAGE }}:${{ github.tag_name }} \
${{ env.DOCKERHUB_IMAGE }}:${{ github.sha }}
- name: Update Docker Hub description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.DOCKERHUB_IMAGE }}

0 comments on commit 3f7fbb2

Please sign in to comment.