Skip to content

Commit 1276f0d

Browse files
authored
Add Dockerhub target to GHA build (#71)
* Add docker push * Change names * Rename file from GHCR
1 parent db4ba85 commit 1276f0d

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

.github/workflows/build_ghcr.yaml renamed to .github/workflows/build_containers.yaml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
matrix:
1313
base:
1414
- {image: 'r-ver', amdtag: '4.2.2', armtag: '4.2.2', outname: 'r-ver'}
15-
- {image: 'rstudio', amdtag: '4.2.2', armtag: 'latest-daily', outname: 'bioconductor'}
15+
- {image: 'rstudio', amdtag: '4.2.2', armtag: 'latest-daily', outname: 'bioconductor_docker'}
1616
- {image: 'tidyverse', amdtag: '4.2.2', armtag: 'N/A', outname: 'tidyverse'}
1717
- {image: 'ml-verse', amdtag: '4.2.2', armtag: 'N/A', outname: 'ml-verse'}
1818
name: Build branch images
@@ -35,20 +35,35 @@ jobs:
3535
username: ${{ github.actor }}
3636
password: ${{ secrets.GITHUB_TOKEN }}
3737

38+
- name: Login to Dockerhub
39+
uses: docker/login-action@v2
40+
with:
41+
username: ${{ secrets.DOCKER_USERNAME }}
42+
password: ${{ secrets.DOCKER_PASSWORD }}
43+
3844
- name: Extract metadata for container image
3945
id: meta
4046
uses: docker/metadata-action@v4
4147
with:
42-
images: ghcr.io/${{ github.repository_owner }}/${{ matrix.base.outname }}
48+
images: ${{ github.repository_owner }}/${{ matrix.base.outname }}
4349
tags: |
4450
type=raw,value={{branch}}
4551
52+
- name: Set comma-separated list with all repository names
53+
id: images
54+
run: |
55+
IMG=${{ steps.meta.outputs.tags }}
56+
REPOLIST="docker.io/$IMG,ghcr.io/$IMG"
57+
SUB="_docker"
58+
# Also add alternative without _docker when in name
59+
echo list=$(if [[ $REPOLIST == *$SUB* ]]; then echo "$REPOLIST,$(echo $REPOLIST | sed 's/_docker//g')"; else echo $REPOLIST; fi) >> $GITHUB_OUTPUT
60+
4661
- name: Set up Docker Buildx
4762
uses: docker/setup-buildx-action@v2
4863
with:
4964
platforms: linux/amd64,linux/arm64
5065

51-
- name: Build and push container image to GHCR
66+
- name: Build and push container image to all repos both arm64 and amd64
5267
uses: docker/build-push-action@v3
5368
with:
5469
build-args: |
@@ -57,20 +72,20 @@ jobs:
5772
amd64_tag=${{ matrix.base.amdtag }}
5873
file: Dockerfile
5974
push: true
60-
tags: ${{ steps.meta.outputs.tags }}
75+
tags: ${{ steps.images.outputs.list }}
6176
labels: ${{ steps.meta.outputs.labels }}
6277
platforms: linux/amd64,linux/arm64
6378
if: matrix.base.armtag != 'N/A'
6479

65-
- name: Build and push container image to GHCR
80+
- name: Build and push container image to all repos amd64 only
6681
uses: docker/build-push-action@v3
6782
with:
6883
build-args: |
6984
BASE_IMAGE=rocker/${{ matrix.base.image }}
7085
amd64_tag=${{ matrix.base.amdtag }}
7186
file: Dockerfile
7287
push: true
73-
tags: ${{ steps.meta.outputs.tags }}
88+
tags: ${{ steps.images.outputs.list }}
7489
labels: ${{ steps.meta.outputs.labels }}
7590
platforms: linux/amd64
7691
if: matrix.base.armtag == 'N/A'

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ FROM ${BASE_IMAGE}:${arm64_tag} AS base-arm64
66

77
FROM ${BASE_IMAGE}:${amd64_tag} AS base-amd64
88

9-
ARG TARGETARCH
9+
ARG TARGETARCH=amd64
1010
FROM base-$TARGETARCH AS base
1111

1212
## Set platform env variable

0 commit comments

Comments
 (0)