Skip to content

Commit 096cb4b

Browse files
committed
Rework GitHub Release and Docker Actions
The universal goal is to make those actions available in forks, remove some cumbersome scripts and unnecessary steps, enable arm64 build and upload to ghcr.io as an alternative container registry. Signed-off-by: Jiaxun Yang <[email protected]>
1 parent 2a5d034 commit 096cb4b

File tree

8 files changed

+76
-328
lines changed

8 files changed

+76
-328
lines changed

.github/workflows/docker.yml

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ on:
99
jobs:
1010
ubuntu:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
packages: write
14+
contents: read
15+
attestations: write
16+
id-token: write
1217
steps:
1318
- name: Print environment
1419
shell: bash
@@ -18,6 +23,8 @@ jobs:
1823
- uses: actions/setup-python@v5
1924
with:
2025
python-version: '3.10'
26+
cache: 'pip'
27+
2128
- name: Install dependencies
2229
run: python3 -m pip install -r docker/requirements.txt
2330
- name: Install opengrok-tools so that pylint can perform the checks
@@ -33,18 +40,46 @@ jobs:
3340
run: black --check docker/*.py
3441
- name: Run isort in check mode
3542
run: isort --settings-file docker/.isort.cfg docker/*.py --check --diff
36-
- name: Build and optionally push Docker image
37-
env:
38-
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
39-
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
40-
OPENGROK_REPO_SLUG: ${{ github.repository }}
41-
OPENGROK_REF: ${{ github.ref }}
42-
run: ./dev/docker.sh
43-
- name: Install Python pre-requisites
44-
run: python3 -m pip install requests
45-
- name: Optionally update README on Docker hub
46-
env:
47-
OPENGROK_REPO_SLUG: ${{ github.repository }}
48-
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
49-
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
50-
run: ./dev/dockerhub_readme.py
43+
- name: Login to GitHub Container Registry
44+
uses: docker/login-action@v3
45+
with:
46+
registry: ghcr.io
47+
username: ${{ github.repository_owner }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
49+
- name: Log in to Docker Hub
50+
uses: docker/login-action@v3
51+
if: ${{ vars.DOCKER_SLUG != '' }} && ${{ github.event_name != 'pull_request' }}
52+
with:
53+
username: ${{ secrets.DOCKER_USERNAME }}
54+
password: ${{ secrets.DOCKER_PASSWORD }}
55+
- name: Extract metadata (tags, labels) for Docker
56+
id: meta
57+
uses: docker/metadata-action@v5
58+
with:
59+
images: |
60+
${{ vars.DOCKER_SLUG }}
61+
ghcr.io/${{ github.repository }}
62+
labels: |
63+
maintainer="https://github.com/oracle/opengrok"
64+
org.opencontainers.image.description="OpenGrok Code Search"
65+
tags: |
66+
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
67+
type=raw,value=master,enable=${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
68+
type=pep440,pattern={{version}},enable=${{ github.event_name == 'release' }}
69+
type=pep440,pattern={{major}}.{{minor}},enable=${{ github.event_name == 'release' }}
70+
type=ref,event=branch
71+
type=ref,event=pr
72+
- name: Set up QEMU
73+
uses: docker/setup-qemu-action@v3
74+
- name: Set up Docker Buildx
75+
uses: docker/setup-buildx-action@v3
76+
- name: Build and push Docker image
77+
id: push
78+
uses: docker/build-push-action@v6
79+
with:
80+
context: .
81+
file: ./Dockerfile
82+
platforms: linux/amd64,linux/arm64
83+
push: ${{ github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/master') }}
84+
tags: ${{ steps.meta.outputs.tags }}
85+
labels: ${{ steps.meta.outputs.labels }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Update Docker Hub Description
2+
on:
3+
push:
4+
branches:
5+
- master
6+
paths:
7+
- docker/README.md
8+
- .github/workflows/dockerhub-description.yml
9+
jobs:
10+
dockerHubDescription:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Docker Hub Description
16+
if: ${{ vars.DOCKER_SLUG != '' }}
17+
uses: peter-evans/dockerhub-description@v4
18+
with:
19+
username: ${{ secrets.DOCKER_USERNAME }}
20+
password: ${{ secrets.DOCKER_PASSWORD }}
21+
repository: ${{ vars.DOCKER_SLUG }}
22+
readme-filepath: ./docker/README.md

.github/workflows/release.yml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
name: Release
22

3-
# TODO: run this only for the oracle/opengrok repository
43
on:
54
release:
65
types: [created]
76

87
jobs:
9-
get_tag:
10-
name: Get tag name
11-
outputs:
12-
tag: ${{ steps.get_tag.outputs.tag }}
13-
runs-on: ubuntu-latest
14-
steps:
15-
- name: Checkout master branch
16-
uses: actions/checkout@v4
17-
- name: Get the tag name
18-
id: get_tag
19-
env:
20-
OPENGROK_REF: ${{ github.ref }}
21-
run: ./dev/ref2tag.sh
228
build:
239
runs-on: ubuntu-latest
24-
needs: get_tag
2510
steps:
2611
- name: Checkout master branch
2712
uses: actions/checkout@v4
@@ -47,18 +32,13 @@ jobs:
4732
run: ./dev/before
4833
- name: Build
4934
run: ./mvnw -DskipTests=true -Dmaven.javadoc.skip=false -B -V package
50-
- name: Get upload URL
51-
id: get_upload_url
52-
env:
53-
OPENGROK_TAG: ${{ needs.get_tag.outputs.tag }}
54-
run: dev/get_upload_url.sh
5535
- name: Upload release tarball
5636
id: upload-release-asset
5737
uses: actions/upload-release-asset@v1
5838
env:
5939
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6040
with:
61-
upload_url: ${{ steps.get_upload_url.outputs.upload_url }}
62-
asset_path: ./distribution/target/opengrok-${{ needs.get_tag.outputs.tag }}.tar.gz
63-
asset_name: opengrok-${{ needs.get_tag.outputs.tag }}.tar.gz
64-
asset_content_type: application/octet-stream
41+
upload_url: ${{ github.event.release.upload_url }}
42+
asset_path: ./distribution/target/opengrok-${{ github.event.release.tag_name }}.tar.gz
43+
asset_name: opengrok-${{ github.event.release.tag_name }}.tar.gz
44+
asset_content_type: application/gzip

dev/docker.sh

Lines changed: 0 additions & 96 deletions
This file was deleted.

dev/dockerhub_readme.py

Lines changed: 0 additions & 122 deletions
This file was deleted.

dev/get_upload_url.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

dev/ref2tag.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)