Skip to content

Commit bec0e85

Browse files
committed
master workflows (docker-push composite action)
1 parent 446ec66 commit bec0e85

2 files changed

Lines changed: 76 additions & 66 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# .github/actions/docker-push/action.yml
2+
name: "Docker Push Composite"
3+
description: "Build and push Docker image to any registry"
4+
runs:
5+
using: "composite"
6+
steps:
7+
# Set up QEMU for multi-architecture builds
8+
- name: Set up QEMU
9+
uses: docker/setup-qemu-action@v3
10+
11+
# Set up Docker Buildx for multi-architecture build support
12+
- name: Set up Docker Buildx
13+
uses: docker/setup-buildx-action@v3
14+
15+
- name: Generate Docker Metadata
16+
id: metadata
17+
uses: docker/metadata-action@v5
18+
with:
19+
images: ${{ inputs.image }}
20+
tags: |
21+
type=ref,event=tag
22+
type=ref,ref=branch
23+
type=semver,pattern={{version}}
24+
type=semver,pattern={{major}}.{{minor}}
25+
flavor: latest=${{ inputs.latest }}
26+
27+
- name: Log in to Docker Registry
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ${{ inputs.registry }}
31+
username: ${{ inputs.username }}
32+
password: ${{ inputs.password }}
33+
34+
- name: Build and push Docker image
35+
uses: docker/build-push-action@v5
36+
with:
37+
context: .
38+
file: ${{ inputs.dockerfile }}
39+
platforms: ${{ inputs.platforms }}
40+
push: true
41+
tags: ${{ steps.metadata.outputs.tags }}
42+
labels: ${{ steps.metadata.outputs.labels }}
43+
44+
inputs:
45+
registry:
46+
description: 'Docker registry URL'
47+
required: true
48+
image:
49+
description: 'Image name'
50+
required: true
51+
username:
52+
description: 'Registry username'
53+
required: true
54+
password:
55+
description: 'Registry password'
56+
required: true
57+
dockerfile:
58+
description: 'Path to Dockerfile'
59+
required: true
60+
platforms:
61+
description: 'Platforms to build'
62+
required: false
63+
default: 'linux/amd64,linux/arm64'
64+
latest:
65+
description: 'Set latest tag'
66+
required: false
67+
default: true

.github/workflows/ci.yml

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ on:
1010
tags:
1111
- "*"
1212

13-
permissions:
14-
contents: read # needed for checkout
15-
packages: write # needed to push to GHCR
16-
1713
jobs:
1814
build:
1915
runs-on: ubuntu-latest
@@ -28,78 +24,25 @@ jobs:
2824
# Checkout the repository
2925
- uses: actions/checkout@v4
3026

31-
# Set up QEMU for multi-architecture builds
32-
- name: Set up QEMU
33-
uses: docker/setup-qemu-action@v3
34-
35-
# Set up Docker Buildx for multi-architecture build support
36-
- name: Set up Docker Buildx
37-
uses: docker/setup-buildx-action@v3
38-
3927
# Registry 1. GitHub Container Registry (GHCR)
40-
- name: Generate Docker Metadata
41-
id: metadata
42-
uses: docker/metadata-action@v5
43-
with:
44-
images: ghcr.io/${{ github.repository }}
45-
tags: |
46-
type=ref,event=tag
47-
type=ref,ref=branch
48-
type=semver,pattern={{version}}
49-
type=semver,pattern={{major}}.{{minor}}
50-
flavor: latest=true
51-
52-
- name: Log in to GHCR
53-
uses: docker/login-action@v3
28+
- name: Build and push to GHCR
29+
uses: ./.github/actions/docker-push
5430
with:
5531
registry: ghcr.io
32+
image: ghcr.io/${{ github.repository }}
5633
username: ${{ github.actor }}
5734
password: ${{ secrets.GITHUB_TOKEN }}
58-
59-
- name: Build and push Docker image to GHCR
60-
uses: docker/build-push-action@v5
61-
with:
62-
context: .
63-
platforms: linux/amd64,linux/arm64 # multi-arch support
64-
file: docker/Dockerfile
65-
push: true
66-
tags: ${{ steps.metadata.outputs.tags }}
67-
labels: ${{ steps.metadata.outputs.labels }}
35+
dockerfile: docker/Dockerfile
6836

6937
# Registry 2. DockerHub (only if credentials are provided)
70-
- name: Generate Docker Metadata
38+
- name: Build and push to DockerHub
39+
uses: ./.github/actions/docker-push
7140
if: ${{ env.DOCKER_USERNAME }}
7241
env:
7342
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
74-
id: metadata2
75-
uses: docker/metadata-action@v5
76-
with:
77-
images: ${{ github.repository }}
78-
tags: |
79-
type=ref,event=tag
80-
type=ref,ref=branch
81-
type=semver,pattern={{version}}
82-
type=semver,pattern={{major}}.{{minor}}
83-
flavor: latest=true
84-
85-
- name: Log in to DockerHub
86-
if: ${{ env.DOCKER_USERNAME }}
87-
env:
88-
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
89-
uses: docker/login-action@v3
9043
with:
44+
registry: docker.io
45+
image: ${{ github.repository }}
9146
username: ${{ secrets.DOCKER_USERNAME }}
9247
password: ${{ secrets.DOCKER_PASSWORD }}
93-
94-
- name: Build and push Docker image to DockerHub
95-
if: ${{ env.DOCKER_USERNAME }}
96-
env:
97-
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
98-
uses: docker/build-push-action@v5
99-
with:
100-
context: .
101-
platforms: linux/amd64,linux/arm64 # multi-arch support
102-
file: docker/Dockerfile
103-
push: true
104-
tags: ${{ steps.metadata2.outputs.tags }}
105-
labels: ${{ steps.metadata2.outputs.labels }}
48+
dockerfile: docker/Dockerfile

0 commit comments

Comments
 (0)