-
Notifications
You must be signed in to change notification settings - Fork 2
116 lines (96 loc) · 4.29 KB
/
pullAndPushImage.yaml
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Pull and Push Image
env:
ONLINE_REGISTER: ghcr.io
ONLINE_REGISTER_USER: ${{ github.actor }}
ONLINE_REGISTER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
on:
workflow_dispatch:
inputs:
source_image:
description: 'Source image to pull (e.g., docker.io/mellanox/tcpdump-rdma)'
required: true
type: string
target_tag:
description: 'Optional: Target tag to use (if empty, will use source image tag)'
required: false
type: string
permissions: write-all
jobs:
pull-and-push:
timeout-minutes: 30
environment: release-base-images
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Set up QEMU
id: qemu
uses: docker/[email protected]
- name: Parse image information
run: |
echo "Processing source image: ${{ github.event.inputs.source_image }}"
# Extract image name without registry and tag
if [[ "${{ github.event.inputs.source_image }}" == *":"* ]]; then
# Image has a tag
SOURCE_IMAGE_NAME=$(echo "${{ github.event.inputs.source_image }}" | cut -d':' -f1)
SOURCE_IMAGE_TAG=$(echo "${{ github.event.inputs.source_image }}" | cut -d':' -f2)
else
# No tag specified, use 'latest'
SOURCE_IMAGE_NAME="${{ github.event.inputs.source_image }}"
SOURCE_IMAGE_TAG="latest"
fi
# Extract the image name without registry prefix
if [[ "${SOURCE_IMAGE_NAME}" == *"/"* ]]; then
# Remove registry prefix if exists
IMAGE_SUFFIX=$(echo "${SOURCE_IMAGE_NAME}" | grep -o '[^/]*$')
else
# No registry prefix
IMAGE_SUFFIX="${SOURCE_IMAGE_NAME}"
fi
# Set target image name with ghcr.io/spidernet-io prefix
TARGET_IMAGE_NAME="ghcr.io/spidernet-io/${IMAGE_SUFFIX}"
# Determine target tag - use input tag if provided, otherwise use source tag
if [[ -n "${{ github.event.inputs.target_tag }}" ]]; then
TARGET_IMAGE_TAG="${{ github.event.inputs.target_tag }}"
echo "Using specified target tag: ${TARGET_IMAGE_TAG}"
else
TARGET_IMAGE_TAG="${SOURCE_IMAGE_TAG}"
echo "Using source image tag: ${TARGET_IMAGE_TAG}"
fi
echo "SOURCE_IMAGE_NAME=${SOURCE_IMAGE_NAME}" >> $GITHUB_ENV
echo "SOURCE_IMAGE_TAG=${SOURCE_IMAGE_TAG}" >> $GITHUB_ENV
echo "TARGET_IMAGE_NAME=${TARGET_IMAGE_NAME}" >> $GITHUB_ENV
echo "TARGET_IMAGE_TAG=${TARGET_IMAGE_TAG}" >> $GITHUB_ENV
echo "Source image: ${SOURCE_IMAGE_NAME}:${SOURCE_IMAGE_TAG}"
echo "Target image: ${TARGET_IMAGE_NAME}:${TARGET_IMAGE_TAG}"
- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
username: ${{ env.ONLINE_REGISTER_USER }}
password: ${{ env.ONLINE_REGISTER_PASSWORD }}
registry: ${{ env.ONLINE_REGISTER }}
- name: Pull source image
run: |
docker pull ${{ github.event.inputs.source_image }}
# Tag the image with the target name and tag
docker tag ${{ github.event.inputs.source_image }} ${{ env.TARGET_IMAGE_NAME }}:${{ env.TARGET_IMAGE_TAG }}
# Also tag as latest if not already latest
if [ "${{ env.TARGET_IMAGE_TAG }}" != "latest" ]; then
docker tag ${{ github.event.inputs.source_image }} ${{ env.TARGET_IMAGE_NAME }}:latest
fi
# List images to verify
docker images
- name: Push image to GitHub Container Registry
run: |
# Push the specific tag
docker push ${{ env.TARGET_IMAGE_NAME }}:${{ env.TARGET_IMAGE_TAG }}
# Push latest tag if not already latest
if [ "${{ env.TARGET_IMAGE_TAG }}" != "latest" ]; then
docker push ${{ env.TARGET_IMAGE_NAME }}:latest
fi
- name: Status
shell: bash
run: |
echo "Successfully pulled and pushed image:"
echo "Source: ${{ github.event.inputs.source_image }}"
echo "Target: ${{ env.TARGET_IMAGE_NAME }}:${{ env.TARGET_IMAGE_TAG }}"