From 18f39ffbe356e2a3acb249ad02a9ae047cef2a63 Mon Sep 17 00:00:00 2001 From: Ivan Pepelnjak Date: Wed, 31 Jul 2024 18:55:52 +0200 Subject: [PATCH] Bug fix: change container tag and PIP option for dev release builds (fixes #1259) --- .devcontainer/Dockerfile | 4 +++- .devcontainer/devcontainer.json | 7 +++++-- .github/get-container-tags.sh | 11 +++++++++++ .github/workflows/devcontainer-build.yml | 6 ++++++ .github/workflows/devcontainer-devc.yml | 1 + .github/workflows/devcontainer-release.yml | 5 +++-- 6 files changed, 29 insertions(+), 5 deletions(-) create mode 100755 .github/get-container-tags.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 957262526..7c8867833 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,5 +1,7 @@ FROM mcr.microsoft.com/devcontainers/python:3.11-bookworm +ARG PIP_OPTIONS +ENV PIP_OPTIONS=${PIP_OPTIONS} ENV NETLAB_DEVICES_FRR_CLAB_GROUP__VARS_NETLAB__MGMT__VRF=False ENV ANSIBLE_CONFIG=./ansible.cfg LABEL org.opencontainers.image.source https://github.com/ipspace/netlab @@ -16,7 +18,7 @@ RUN sudo mkdir -p -m 755 /etc/apt/keyrings \ # install containerlab and tools RUN apt update && \ apt install -y python3-pip && \ - python3 -m pip install --break-system-packages networklab && \ + python3 -m pip install --break-system-packages $PIP_OPTIONS networklab && \ apt install -y --no-install-recommends containerlab \ btop \ gh \ diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 0be2d5e1c..e375d5fbb 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,8 +2,11 @@ // README at: https://github.com/devcontainers/templates/tree/main/src/docker-in-docker { "build": { - "dockerfile": "./Dockerfile" - }, + "dockerfile": "./Dockerfile", + "args": { + "PIP_OPTIONS": "${localEnv:PIP_OPTIONS}" + } + }, "name": "netlab development container", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile "remoteUser": "vscode", diff --git a/.github/get-container-tags.sh b/.github/get-container-tags.sh new file mode 100755 index 000000000..9f9af11b8 --- /dev/null +++ b/.github/get-container-tags.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# +TAG=${1#release_} +XTAG=latest +if [[ $TAG == *"dev"* ]]; then + XTAG=dev + echo "PIP_OPTIONS=--pre" +else + echo "PIP_OPTIONS=" +fi +echo "IMAGE_TAG=$TAG,$XTAG" diff --git a/.github/workflows/devcontainer-build.yml b/.github/workflows/devcontainer-build.yml index 0f43dec81..5cdd3306c 100644 --- a/.github/workflows/devcontainer-build.yml +++ b/.github/workflows/devcontainer-build.yml @@ -7,12 +7,16 @@ on: docker-tags: required: True type: string + pip-options: + required: False + type: string secrets: GHCR_TOKEN: required: True env: REGISTRY: ghcr.io + PIP_OPTIONS: ${{ inputs.pip-options }} jobs: build: @@ -35,3 +39,5 @@ jobs: imageName: ghcr.io/${{ github.repository }}/devcontainer imageTag: ${{ inputs.docker-tags }} push: always + env: | + PIP_OPTIONS diff --git a/.github/workflows/devcontainer-devc.yml b/.github/workflows/devcontainer-devc.yml index cb07638a8..201cb3d02 100644 --- a/.github/workflows/devcontainer-devc.yml +++ b/.github/workflows/devcontainer-devc.yml @@ -13,5 +13,6 @@ jobs: uses: ./.github/workflows/devcontainer-build.yml with: docker-tags: devc + pip-options: --pre secrets: GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }} diff --git a/.github/workflows/devcontainer-release.yml b/.github/workflows/devcontainer-release.yml index 97b4d1dbd..ad0dc513e 100644 --- a/.github/workflows/devcontainer-release.yml +++ b/.github/workflows/devcontainer-release.yml @@ -16,12 +16,13 @@ jobs: steps: - name: Find release tag id: release_tag - run: echo "IMAGE_TAG=${GITHUB_REF_NAME#release_}" >> $GITHUB_OUTPUT + run: ./.github/get-container-tags.sh $GITHUB_REF_NAME >> $GITHUB_OUTPUT build: needs: [ setup ] uses: ./.github/workflows/devcontainer-build.yml with: - docker-tags: ${{ needs.setup.outputs.IMAGE_TAG }},latest + docker-tags: ${{ needs.setup.outputs.IMAGE_TAG }} + pip-options: ${{ needs.setup.outputs.PIP_OPTIONS }} secrets: GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}