Skip to content

Commit 9cd4db6

Browse files
committed
build: update build config
1 parent d1f398e commit 9cd4db6

3 files changed

Lines changed: 40 additions & 23 deletions

File tree

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
1+
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference
22
version: 2
33
updates:
44
- package-ecosystem: github-actions

.github/workflows/build.yml

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44
# SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/docker-openldap
55
#
6-
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
6+
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions
77
name: Build
88

99
on:
@@ -26,28 +26,30 @@ on:
2626
- '.github/*.yml'
2727
- '.github/workflows/stale.yml'
2828
schedule:
29-
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
29+
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
3030
- cron: '0 17 * * 3'
3131
workflow_dispatch:
32-
# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
32+
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_dispatch
3333

3434
defaults:
3535
run:
3636
shell: bash
3737

3838
env:
39-
DOCKER_IMAGE_REPO: vegardit/openldap
39+
DOCKER_REPO_NAME: openldap
4040
TRIVY_CACHE_DIR: ~/.trivy/cache
4141

4242
jobs:
4343

4444
###########################################################
4545
build:
4646
###########################################################
47-
4847
runs-on: ubuntu-latest # https://github.com/actions/runner-images#available-images
4948
timeout-minutes: 10
5049

50+
permissions:
51+
packages: write
52+
5153
steps:
5254
- name: "Show: GitHub context"
5355
env:
@@ -99,11 +101,13 @@ jobs:
99101

100102

101103
- name: "Determine if docker images shall be published"
104+
id: docker_push_actions
102105
run: |
103106
# ACT -> https://nektosact.com/usage/index.html#skipping-steps
104107
set -x
105108
if [[ $GITHUB_REF_NAME == 'main' && $GITHUB_EVENT_NAME != 'pull_request' && -z "$ACT" ]]; then
106109
echo "DOCKER_PUSH_GHCR=true" >> "$GITHUB_ENV"
110+
echo "DOCKER_PUSH_GHCR=true" >> $GITHUB_OUTPUT
107111
if [[ -n "${{ secrets.DOCKER_HUB_USERNAME }}" ]]; then
108112
echo "DOCKER_PUSH=true" >> "$GITHUB_ENV"
109113
fi
@@ -124,28 +128,41 @@ jobs:
124128
with:
125129
registry: ghcr.io
126130
username: ${{ github.actor }}
127-
password: ${{ github.token }}
131+
password: ${{ secrets.GITHUB_TOKEN }}
128132

129133

130134
- name: Build docker image
131135
env:
132-
TRIVY_GITHUB_TOKEN: ${{ github.token }}
136+
DOCKER_IMAGE_REPO: ${{ github.repository_owner }}/${{ env.DOCKER_REPO_NAME }}
137+
TRIVY_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133138
run: bash build-image.sh
134139

140+
outputs:
141+
DOCKER_PUSH_GHCR: ${{ steps.docker_push_actions.outputs.DOCKER_PUSH_GHCR }}
142+
143+
144+
###########################################################
145+
delete-untagged-images:
146+
###########################################################
147+
runs-on: ubuntu-latest # https://github.com/actions/runner-images#available-images
148+
timeout-minutes: 5
149+
needs: [build]
150+
if: ${{ needs.build.outputs.DOCKER_PUSH_GHCR }}
151+
152+
concurrency:
153+
group: ${{ github.workflow }}
154+
cancel-in-progress: false
155+
156+
permissions:
157+
packages: write
135158

159+
steps:
136160
- name: Delete untagged images
137-
uses: actions/github-script@v7
138-
if: ${{ env.DOCKER_PUSH_GHCR }}
139-
continue-on-error: true
161+
uses: dataaxiom/ghcr-cleanup-action@v1
140162
with:
141-
github-token: ${{ secrets.GHA_DELETE_PACKAGES }}
142-
script: |
143-
const imageName = /[^/]*$/.exec(process.env.DOCKER_IMAGE_REPO)[0]
144-
const basePath = `/orgs/${{ github.repository_owner }}/packages/container/${imageName}/versions`
145-
for (version of (await github.request(`GET ${basePath}`, { per_page: 100 })).data) {
146-
if (version.metadata.container.tags.length == 0) {
147-
console.log(`deleting ${version.name}...`)
148-
const delResponse = await github.request(`DELETE ${basePath}/${version.id}`)
149-
console.log(`status: ${delResponse.status}`)
150-
}
151-
}
163+
package: ${{ env.DOCKER_REPO_NAME }}
164+
delete-untagged: true
165+
delete-partial-images: true
166+
delete-ghost-images: true
167+
delete-orphaned-images: true
168+
validate: true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,4 @@ Individual files contain the following tag instead of the full license text:
362362
SPDX-License-Identifier: Apache-2.0
363363
```
364364
365-
This enables machine processing of license information based on the SPDX License Identifiers that are available here: https://spdx.org/licenses/.
365+
This enables machine processing of license information based on the SPDX License Identifiers that are available here: https://spdx.org/licenses/.

0 commit comments

Comments
 (0)