|
1 | 1 | name: Publish netconf-simulator |
| 2 | + |
2 | 3 | on: |
3 | 4 | workflow_dispatch: |
4 | 5 | inputs: |
5 | 6 | version: |
6 | 7 | description: Desired version of published docker image & helm charts, e.g. "XX.YY.ZZ" |
7 | 8 | required: true |
8 | 9 | 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. |
10 | 11 | default: "true" |
11 | 12 | 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. |
14 | 15 | default: default |
15 | 16 | required: true |
16 | 17 |
|
17 | 18 | jobs: |
18 | 19 | publish-docker-helm: |
19 | 20 | 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" |
23 | 25 | 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 | + |
27 | 29 | 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 }} |
30 | 34 |
|
31 | 35 | - name: Set up JDK 21 |
32 | | - uses: actions/setup-java@v3 |
| 36 | + uses: actions/setup-java@v4 |
33 | 37 | with: |
34 | 38 | java-version: 21 |
35 | 39 | distribution: 'temurin' |
36 | 40 |
|
37 | 41 | - name: Build lighty-netconf-simulator |
38 | | - shell: bash |
39 | 42 | run: | |
40 | 43 | echo "Building lighty-netconf-simulator..." |
41 | | - mvn install -DskipTests |
| 44 | + mvn -B install -DskipTests |
42 | 45 |
|
43 | | - - name: Run docker:build... |
44 | | - shell: bash |
| 46 | + - name: Build Docker image |
45 | 47 | 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 |
61 | 56 | 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 |
73 | 69 | 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 |
77 | 79 | 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 |
93 | 82 | 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