-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (46 loc) · 2 KB
/
udocker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: Check Dockerfile Base Image Updates
on:
schedule:
- cron: '0 0 * * *' # Run daily
workflow_dispatch: # Allows manual triggering of the workflow
jobs:
check-updates:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for base image updates
id: check
run: |
# Read the current base image from the Dockerfile
BASE_IMAGE=$(grep -oP 'FROM \K.*' Dockerfile)
echo "Base image from Dockerfile: $BASE_IMAGE"
IMAGE_NAME=$(echo $BASE_IMAGE | cut -d':' -f1)
echo "Image name extracted: $IMAGE_NAME"
CURRENT_TAG=$(echo $BASE_IMAGE | cut -d':' -f2)
echo "Current tag extracted: $CURRENT_TAG"
# Fetch tags from Docker Hub
TAGS_JSON=$(wget -q https://registry.hub.docker.com/v1/repositories/$IMAGE_NAME/tags -O -)
echo "Tags fetched from Docker Hub: $TAGS_JSON"
# Parse the tags and find the latest one
LATEST_TAG=$(echo $TAGS_JSON | jq -r "[.[] | select(.name | test(\"^$CURRENT_TAG[.]\")) | .name] | max_by(split(\".\") | map(tonumber))")
if [ -z "$LATEST_TAG" ]; then
echo "No newer tags found for the image $IMAGE_NAME with the tag starting $CURRENT_TAG."
echo "updated=false" >> $GITHUB_ENV
else
echo "A newer base image tag is available: $LATEST_TAG"
sed -i "s|$BASE_IMAGE|$IMAGE_NAME:$LATEST_TAG|g" Dockerfile
# Check the Dockerfile after sed operation
echo "Dockerfile updated content:"
cat Dockerfile
# Use environment file to set the output
echo "updated=true" >> $GITHUB_ENV
echo "new_tag=$LATEST_TAG" >> $GITHUB_ENV
fi
- name: Commit and push if Dockerfile changed
if: env.updated == 'true'
run: |
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@github.com'
git add Dockerfile
git commit -m "