Skip to content

Commit 8777a02

Browse files
authored
Merge pull request #97 from axiom-data-science/gha-simplification
Simplify GHA Docker publishing
2 parents 4201283 + 47ae8d2 commit 8777a02

File tree

2 files changed

+52
-116
lines changed

2 files changed

+52
-116
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Publish Docker images
2+
description: Publish Docker images to Docker Hub
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Docker meta
7+
id: meta
8+
uses: docker/metadata-action@v5
9+
with:
10+
images: |
11+
axiom/docker-erddap
12+
flavor: |
13+
suffix=-jdk21-openjdk
14+
suffixLatest=true
15+
tags: |
16+
type=raw,value=latest,enable={{is_default_branch}}
17+
type=ref,event=tag
18+
19+
- name: Login to Docker Hub
20+
uses: docker/login-action@v3
21+
with:
22+
username: ${{ secrets.DOCKER_USERNAME }}
23+
password: ${{ secrets.DOCKER_PASSWORD }}
24+
25+
- name: Push to Docker Hub
26+
uses: docker/build-push-action@v6
27+
with:
28+
push: true
29+
platforms: linux/amd64,linux/arm64/v8
30+
tags: ${{ steps.meta.outputs.tags }}
31+
labels: ${{ steps.meta.outputs.labels }}
32+
cache-from: type=gha
33+
cache-to: type=gha,mode=max
34+
35+
- name: Update repo description
36+
uses: peter-evans/dockerhub-description@v4
37+
with:
38+
username: ${{ secrets.DOCKER_USERNAME }}
39+
password: ${{ secrets.DOCKER_PASSWORD }}
40+
repository: axiom/docker-erddap

.github/workflows/build_docker_image.yml

Lines changed: 12 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -7,143 +7,39 @@ 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-
37-
- name: Docker meta
38-
id: meta
39-
uses: docker/metadata-action@v5
40-
with:
41-
images: |
42-
axiom/docker-erddap
43-
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' }}
46-
4720
- name: Set up Docker Buildx
4821
uses: docker/setup-buildx-action@v3
4922

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-
58-
- name: Build image
23+
- name: Build image for testing
5924
uses: docker/build-push-action@v6
6025
with:
6126
push: false
62-
platforms: ${{ matrix.platform }}
63-
tags: ${{ steps.meta.outputs.tags }}
64-
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 }
27+
tags: docker-erddap-test
28+
cache-from: type=gha
29+
cache-to: type=gha,mode=max
6930
outputs: type=docker
7031

7132
- name: Run Docker Image in Background
72-
if: matrix.platform == 'linux/amd64'
73-
run: docker run -d -p 8080:8080 ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
33+
run: docker run -d -p 8080:8080 docker-erddap-test
7434

7535
- name: Check that ERDDAP Docker Image will return a 200
76-
if: matrix.platform == 'linux/amd64'
7736
uses: ifaxity/wait-on-action@v1
7837
timeout-minutes: 1
7938
with:
8039
resource: http://localhost:8080/erddap/index.html
8140

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
41+
- name: Publish Docker images
42+
if: |
43+
((github.event_name == 'release' && github.event.action == 'published') || github.ref == 'refs/heads/main')
44+
&& github.repository == 'axiom-data-science/docker-erddap'
45+
uses: ./.github/actions/publish_docker_image

0 commit comments

Comments
 (0)