Skip to content

Commit 2e67a37

Browse files
committed
Simplify GHA Docker publishing
1 parent 4201283 commit 2e67a37

File tree

2 files changed

+38
-104
lines changed

2 files changed

+38
-104
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish Docker images
2+
description: Publish Docker images to Docker Hub
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Login to Docker Hub
7+
uses: docker/login-action@v3
8+
with:
9+
username: ${{ secrets.DOCKER_USERNAME }}
10+
password: ${{ secrets.DOCKER_PASSWORD }}
11+
12+
- name: Push to Docker Hub
13+
uses: docker/build-push-action@v6
14+
with:
15+
push: true
16+
platforms: linux/amd64,linux/arm64/v8
17+
tags: ${{ steps.meta.outputs.tags }}
18+
19+
- name: Update repo description
20+
uses: peter-evans/dockerhub-description@v4
21+
with:
22+
username: ${{ secrets.DOCKER_USERNAME }}
23+
password: ${{ secrets.DOCKER_PASSWORD }}
24+
repository: axiom/docker-erddap

.github/workflows/build_docker_image.yml

Lines changed: 14 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -7,143 +7,53 @@ on:
77
branches:
88
- main
99
release:
10-
types: [published]
11-
env:
12-
BUILDX_CACHE: /tmp/.buildx-cache
13-
CACHE_KEY: docker-erddap-buildx-
10+
types:
11+
- published
1412

1513
jobs:
1614
build:
1715
name: Build and test Docker Image
1816
runs-on: ubuntu-22.04
1917
timeout-minutes: 10
2018

21-
strategy:
22-
matrix:
23-
include:
24-
#amd64
25-
- platform: "linux/amd64"
26-
tag: "${{ vars.DOCKER_TAG }}"
27-
base: "${{ vars.TOMCAT_AMD64_IMAGE }}"
28-
#arm64/v8
29-
- platform: "linux/arm64/v8"
30-
tag: "${{ vars.DOCKER_TAG }}"
31-
base: "${{ vars.TOMCAT_ARM64_IMAGE }}"
32-
3319
steps:
34-
- name: Checkout
35-
uses: actions/checkout@v4
36-
3720
- name: Docker meta
3821
id: meta
3922
uses: docker/metadata-action@v5
4023
with:
4124
images: |
4225
axiom/docker-erddap
26+
flavor: |
27+
suffix=-jdk21-openjdk
4328
tags: |
44-
type=raw,value=${{ matrix.tag }},prefix=latest-
45-
type=raw,value=${{ github.event.release.tag_name }},suffix=-${{ matrix.tag }},enable=${{ github.event_name == 'release' && github.event.action == 'published' }}
29+
type=raw,value=latest,enable={{is_default_branch}}
30+
type=ref,event=tag
4631
4732
- name: Set up Docker Buildx
4833
uses: docker/setup-buildx-action@v3
4934

50-
- name: Cache Docker layers
51-
uses: actions/cache@v4
52-
with:
53-
path: ${ BUILDX_CACHE }
54-
key: ${ CACHE_KEY }${{ github.sha }}
55-
restore-keys: |
56-
${ CACHE_KEY }
57-
5835
- name: Build image
5936
uses: docker/build-push-action@v6
6037
with:
6138
push: false
62-
platforms: ${{ matrix.platform }}
39+
platforms: linux/amd64,linux/arm64/v8
6340
tags: ${{ steps.meta.outputs.tags }}
6441
labels: ${{ steps.meta.outputs.labels }}
65-
build-args: |
66-
BASE_IMAGE=${{ matrix.base }}
67-
cache-from: type=local,src=${ BUILDX_CACHE }
68-
cache-to: type=local,dest=${ BUILDX_CACHE }
42+
cache-from: type=gha
43+
cache-to: type=gha,mode=max
6944
outputs: type=docker
7045

7146
- name: Run Docker Image in Background
72-
if: matrix.platform == 'linux/amd64'
7347
run: docker run -d -p 8080:8080 ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
7448

7549
- name: Check that ERDDAP Docker Image will return a 200
76-
if: matrix.platform == 'linux/amd64'
7750
uses: ifaxity/wait-on-action@v1
7851
timeout-minutes: 1
7952
with:
8053
resource: http://localhost:8080/erddap/index.html
8154

82-
push:
83-
name: Push latest image to Docker Hub
84-
runs-on: ubuntu-22.04
85-
timeout-minutes: 10
86-
needs: build
87-
if: (github.event_name == 'release' && github.event.action == 'published') || (github.ref == 'refs/heads/main') && github.repository == 'axiom-data-science/docker-erddap'
88-
89-
strategy:
90-
matrix:
91-
include:
92-
#amd64
93-
- platform: "linux/amd64"
94-
tag: "${{ vars.DOCKER_TAG }}"
95-
base: "${{ vars.TOMCAT_AMD64_IMAGE }}"
96-
#arm64/v8
97-
- platform: "linux/arm64/v8"
98-
tag: "${{ vars.DOCKER_TAG }}"
99-
base: "${{ vars.TOMCAT_ARM64_IMAGE }}"
100-
101-
steps:
102-
- name: Checkout
103-
uses: actions/checkout@v4
104-
105-
- name: Docker meta
106-
id: meta
107-
uses: docker/metadata-action@v5
108-
with:
109-
images: |
110-
axiom/docker-erddap
111-
tags: |
112-
type=raw,value=${{ matrix.tag }},prefix=latest-
113-
type=raw,value=${{ github.event.release.tag_name }},suffix=-${{ matrix.tag }},enable=${{ github.event_name == 'release' && github.event.action == 'published' }}
114-
115-
- name: Set up Docker Buildx
116-
uses: docker/setup-buildx-action@v3
117-
118-
- name: Cache Docker layers
119-
uses: actions/cache@v4
120-
with:
121-
path: ${ BUILDX_CACHE }
122-
key: ${ CACHE_KEY }${{ github.sha }}
123-
restore-keys: |
124-
${ CACHE_KEY }
125-
126-
- name: Login to Docker Hub
127-
uses: docker/login-action@v3
128-
with:
129-
username: ${{ secrets.DOCKER_USERNAME }}
130-
password: ${{ secrets.DOCKER_PASSWORD }}
131-
132-
- name: Push to Docker Hub
133-
uses: docker/build-push-action@v6
134-
with:
135-
push: true
136-
platforms: ${{ matrix.platform }}
137-
tags: ${{ steps.meta.outputs.tags }}
138-
labels: ${{ steps.meta.outputs.labels }}
139-
build-args: |
140-
BASE_IMAGE=${{ matrix.base }}
141-
cache-from: type=local,src=${ BUILDX_CACHE }
142-
cache-to: type=local,dest=${ BUILDX_CACHE }
143-
144-
- name: Update repo description
145-
uses: peter-evans/dockerhub-description@v4
146-
with:
147-
username: ${{ secrets.DOCKER_USERNAME }}
148-
password: ${{ secrets.DOCKER_PASSWORD }}
149-
repository: axiom/docker-erddap
55+
- name: Publish Docker images
56+
if: |
57+
((github.event_name == 'release' && github.event.action == 'published') || github.ref == 'refs/heads/main')
58+
&& github.repository == 'axiom-data-science/docker-erddap'
59+
uses: .github/actions/publish_docker_image

0 commit comments

Comments
 (0)