Skip to content

Commit 89b8f0e

Browse files
committed
Fix GHCR authentication in netconf-simulator publish workflow
Correct the GitHub Actions workflow to use docker/login-action@v3 for proper authentication to GitHub Container Registry. Previously, the workflow attempted to pass the token directly via docker login, causing authentication failures. JIRA: LIGHTY-385 Signed-off-by: tobias.pobocik [email protected] Signed-off-by: tobias.pobocik <[email protected]>
1 parent d26f1ce commit 89b8f0e

File tree

1 file changed

+55
-61
lines changed

1 file changed

+55
-61
lines changed
Lines changed: 55 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,88 @@
11
name: Publish netconf-simulator
2+
23
on:
34
workflow_dispatch:
45
inputs:
56
version:
67
description: Desired version of published docker image & helm charts, e.g. "XX.YY.ZZ"
78
required: true
89
image-tag-latest:
9-
description: Should be this docker labeled with tag latest? Enter `true` if the tag `latest` should be added for image.
10+
description: Should this docker image be labeled with tag latest? Enter `true` if yes.
1011
default: "true"
1112
required: true
12-
publish-access-key:
13-
description: The branch, tag or SHA to checkout. (if "default" the selected branch will be used)
13+
checkout-ref:
14+
description: The branch, tag, or SHA to checkout. Use "default" to use the current branch.
1415
default: default
1516
required: true
1617

1718
jobs:
1819
publish-docker-helm:
1920
runs-on: ubuntu-latest
20-
defaults:
21-
run:
22-
shell: bash
21+
permissions:
22+
contents: read
23+
packages: write
24+
name: "Publish netconf-simulator docker image"
2325
env:
24-
IMAGE_NAME: "lighty-network-topology-device"
25-
PUBLISH_ACCESS_KEY: ${{ secrets.MM_PKG_WRITE }}
26-
name: "Publish netconf-simulator docker image. Checkout-ref: ${{ github.event.inputs.publish-access-key }}"
26+
IMAGE_NAME: "netconf-simulator"
27+
REGISTRY: "ghcr.io/pantheontech"
28+
2729
steps:
28-
- name: Checkout code
29-
uses: actions/checkout@v3
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
with:
33+
ref: ${{ github.event.inputs.checkout-ref != 'default' && github.event.inputs.checkout-ref || github.ref_name }}
3034

3135
- name: Set up JDK 21
32-
uses: actions/setup-java@v3
36+
uses: actions/setup-java@v4
3337
with:
3438
java-version: 21
3539
distribution: 'temurin'
3640

3741
- name: Build lighty-netconf-simulator
38-
shell: bash
3942
run: |
4043
echo "Building lighty-netconf-simulator..."
41-
mvn install -DskipTests
44+
mvn -B install -DskipTests
4245
43-
- name: Run docker:build...
44-
shell: bash
46+
- name: Build Docker image
4547
run: |
46-
47-
echo "Image name set to:" ${{ env.IMAGE_NAME }}
48-
49-
DOCKER_IMAGE_NAME=${{env.IMAGE_NAME}}
50-
DOCKER_IMAGE_NAME_TAG=$(echo $DOCKER_IMAGE_NAME:${{ inputs.version }})
51-
DOCKER_IMAGE_NAME_GHCR=$(echo ghcr.io/pantheontech/${{ env.IMAGE_NAME }})
52-
DOCKER_IMAGE_NAME_GHCR_TAG=$(echo $DOCKER_IMAGE_NAME_GHCR:${{ inputs.version }})
53-
54-
echo "docker build -t $DOCKER_IMAGE_NAME ."
55-
docker build -t $DOCKER_IMAGE_NAME .
56-
57-
echo "Docker image tag:" $DOCKER_IMAGE_NAME_GHCR $DOCKER_IMAGE_NAME_GHCR_TAG
58-
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME_TAG
59-
if [ "${{ inputs.image-tag-latest }}" = 'true' ]; then
60-
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:latest
48+
echo "Building Docker image..."
49+
VERSION=${{ inputs.version }}
50+
IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
51+
52+
docker build -t ${IMAGE}:${VERSION} .
53+
54+
if [ "${{ inputs.image-tag-latest }}" = "true" ]; then
55+
docker tag ${IMAGE}:${VERSION} ${IMAGE}:latest
6156
fi
62-
docker images | grep $DOCKER_IMAGE_NAME
63-
- name: List docker images
64-
shell: bash
65-
run: |
66-
docker images
67-
- name: Docker log in (ghcr.io)
68-
shell: bash
69-
run: |
70-
echo ${{ inputs.publish-access-key}} | docker login --username ${{ github.actor }} --password-stdin ghcr.io
71-
- name: Publish docker image (ghcr.io)
72-
shell: bash
57+
58+
echo "Built images:"
59+
docker images ${IMAGE}
60+
61+
- name: Log in to GitHub Container Registry
62+
uses: docker/login-action@v3
63+
with:
64+
registry: ghcr.io
65+
username: ${{ github.actor }}
66+
password: ${{ secrets.GITHUB_TOKEN }}
67+
68+
- name: Push Docker image
7369
run: |
74-
docker push $DOCKER_IMAGE_NAME_GHCR_TAG
75-
if [ "${{ inputs.image-tag-latest }}" = 'true' ]; then
76-
docker push $DOCKER_IMAGE_NAME_GHCR:latest
70+
IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
71+
VERSION=${{ inputs.version }}
72+
73+
echo "Pushing ${IMAGE}:${VERSION}"
74+
docker push ${IMAGE}:${VERSION}
75+
76+
if [ "${{ inputs.image-tag-latest }}" = "true" ]; then
77+
echo "Pushing ${IMAGE}:latest"
78+
docker push ${IMAGE}:latest
7779
fi
78-
- name: Check if docker image is pullable (ghcr.io)
79-
shell: bash
80-
run: |
81-
docker rmi $DOCKER_IMAGE_NAME_GHCR_TAG
82-
docker pull $DOCKER_IMAGE_NAME_GHCR_TAG
83-
- name: Install yq (yaml processor)
84-
shell: bash
85-
run: |
86-
sudo snap install yq
87-
- name: Set image.name, image.version in values.yaml of helm chart
88-
shell: bash
89-
run: |
90-
yq eval '.image.name="ghcr.io/pantheontech/$'"IMAGE_NAME"'" | .image.version="'${{ inputs.version }}'"' "${{ inputs.app-helm-values-path }}" -i
91-
- name: Print values.yaml
92-
shell: bash
80+
81+
- name: Verify image pull works
9382
run: |
94-
cat -A ${{ inputs.app-helm-values-path }}
83+
IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
84+
VERSION=${{ inputs.version }}
85+
86+
echo "Testing pull of ${IMAGE}:${VERSION}"
87+
docker rmi ${IMAGE}:${VERSION} || true
88+
docker pull ${IMAGE}:${VERSION}

0 commit comments

Comments
 (0)