Skip to content

Commit 8fe1693

Browse files
committed
Improve CI Docker Build
1 parent 6012bde commit 8fe1693

File tree

3 files changed

+56
-21
lines changed

3 files changed

+56
-21
lines changed

.github/workflows/build.yml

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
name: Build Docker Images
22

33
env:
4-
BASE_TAG: ghcr.io/${{ github.repository_owner }}/database-backup
4+
DOCKERHUB_TAG: 'jandi/database-backup'
5+
GITHUB_TAG: 'ghcr.io/jan-di/database-backup'
6+
PLATFORMS: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
57

68
on:
79
push:
8-
branches:
9-
- master
10+
branches:
11+
- 'main'
12+
tags:
13+
- 'v*'
14+
pull_request:
15+
branches:
16+
- 'main'
1017

1118
jobs:
1219
multi:
@@ -16,25 +23,50 @@ jobs:
1623
name: Checkout
1724
uses: actions/checkout@v2
1825
-
19-
name: Set up QEMU
20-
uses: docker/setup-qemu-action@v1
26+
name: Docker Metadata
27+
id: docker_meta
28+
uses: docker/metadata-action@v3
29+
with:
30+
images: |
31+
${{ env.DOCKERHUB_TAG }}
32+
${{ env.GITHUB_TAG }}
33+
tags: |
34+
type=ref,event=branch
35+
type=ref,event=pr
36+
type=semver,pattern={{version}}
37+
type=semver,pattern={{major}}.{{minor}}
38+
type=semver,pattern={{major}}
39+
type=sha
2140
-
22-
name: Set up Docker Buildx
23-
uses: docker/setup-buildx-action@v1
41+
name: Login to DockerHub
42+
if: github.event_name != 'pull_request'
43+
uses: docker/login-action@v1
44+
with:
45+
username: ${{ secrets.DOCKERHUB_USERNAME }}
46+
password: ${{ secrets.DOCKERHUB_TOKEN }}
2447
-
2548
name: Login to GitHub Container Registry
49+
if: github.event_name != 'pull_request'
2650
uses: docker/login-action@v1
2751
with:
2852
registry: ghcr.io
2953
username: ${{ github.repository_owner }}
30-
password: ${{ secrets.CR_PAT }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
-
56+
name: Set up QEMU
57+
uses: docker/setup-qemu-action@v1
58+
-
59+
name: Set up Docker Buildx
60+
uses: docker/setup-buildx-action@v1
3161
-
3262
name: Build and push
3363
uses: docker/build-push-action@v2
3464
with:
35-
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
36-
push: true
37-
cache-from: type=registry,ref=${{ env.BASE_TAG }}:latest
65+
context: .
66+
file: ./Dockerfile
67+
push: ${{ github.event_name != 'pull_request' }}
68+
tags: ${{ steps.docker_meta.outputs.tags }}
69+
labels: ${{ steps.docker_meta.outputs.labels }}
70+
platforms: ${{ env.PLATFORMS }}
71+
cache-from: type=registry,ref=${{ env.GITHUB_TAG }}:main
3872
cache-to: type=inline
39-
tags: |
40-
${{ env.BASE_TAG }}:latest

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
FROM python:3.9-alpine
22

3-
LABEL org.opencontainers.image.ref.name="jan-di/database-backup" \
4-
org.opencontainers.image.licenses="MIT" \
5-
org.opencontainers.image.documentation="https://github.com/jan-di/docker-database-backup/blob/master/README.md" \
6-
org.opencontainers.image.source="https://github.com/jan-di/docker-database-backup"
3+
LABEL org.opencontainers.image.ref.name="jan-di/database-backup"
74

85
RUN set -eux; \
96
apk --no-cache add \

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# Docker Database Backup
22

3-
[![](https://img.shields.io/github/workflow/status/jan-di/docker-database-backup/Build%20Docker%20Images?style=flat)](https://github.com/jan-di/docker-database-backup/actions/workflows/build.yml)
4-
[![](https://img.shields.io/github/license/jan-di/docker-database-backup?style=flat)](https://github.com/jan-di/docker-database-backup/blob/master/LICENSE)
3+
[![Source](https://badgen.net/badge/icon/Source?icon=github&label)](https://github.com/jan-di/docker-database-backup)
4+
[![Checks](https://badgen.net/github/checks/jan-di/docker-database-backup)](https://github.com/jan-di/docker-database-backup/actions/workflows/build-docker-image.yml)
5+
[![Release](https://badgen.net/github/release/jan-di/docker-database-backup/stable)](https://github.com/jan-di/docker-database-backup/releases)
6+
[![Last Commit](https://badgen.net/github/last-commit/jan-di/docker-database-backup/main)](https://github.com/jan-di/docker-database-backup/commits/main)
7+
[![License](https://badgen.net/github/license/jan-di/docker-database-backup)](https://github.com/jan-di/docker-database-backup/blob/main/LICENSE)
58

6-
A dockerized service to automatically backup all of your database containers.
9+
Dockerized service to automatically backup all of your database containers.
710

8-
Docker Image: `ghcr.io/jan-di/database-backup`
11+
Docker Image Tags:
12+
13+
- `jandi/database-backup` [Docker Hub](https://hub.docker.com/r/jandi/docker-database-backup)
14+
- `ghcr.io/jan-di/database-backup` [GitHub Container Registry](https://github.com/jan-di/docker-database-backup/pkgs/container/docker-database-backup)
915

1016
## Service Configuration
1117

0 commit comments

Comments
 (0)