diff --git a/.github/actions/create-local-registry/insecure/action.yaml b/.github/actions/create-local-registry/insecure/action.yaml new file mode 100644 index 00000000000..5bace3a2f3b --- /dev/null +++ b/.github/actions/create-local-registry/insecure/action.yaml @@ -0,0 +1,94 @@ +name: "Create a secure local registry" +description: | + This action creates a local registry for the images to be pushed to. + It uses the `docker` CLI to create a registry container and then starts it. + The registry is then available at `localhost:5000` by default. +inputs: + registry-name: + description: "The name of the local registry" + required: true + default: "radius-registry" + registry-server: + description: "The server name for the local registry" + required: true + default: "localhost" + registry-port: + description: "The port for the local registry" + required: true + default: "5000" +runs: + using: "composite" + steps: + - name: Create certificates for local registry + shell: bash + run: | + create_openssl_cfg() { + CFG=$( + cat <<'EOF' + [req] + distinguished_name = subject + x509_extensions = x509_ext + prompt = no + + [subject] + CN = localhost + + [x509_ext] + basicConstraints = critical, CA:TRUE + subjectKeyIdentifier = hash + authorityKeyIdentifier = keyid:always, issuer:always + keyUsage = critical, cRLSign, digitalSignature, keyCertSign + nsComment = "OpenSSL Generated Certificate" + subjectAltName = @alt_names + + [alt_names] + DNS.1 = ${{ inputs.registry-name }} + DNS.2 = ${{ inputs.registry-server }} + EOF + ) + echo "$CFG" + } + + # Create a temporary directory to store the certificates + temp_cert_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'temp_cert_dir') + echo "TEMP_CERT_DIR=$temp_cert_dir" >> $GITHUB_ENV + + pushd $temp_cert_dir + # Create the directory for the certificates + mkdir -p certs/${{ inputs.registry-server }} + + echo "==== Generate the openssl config" + create_openssl_cfg >req.cnf + + echo "==== Create the self signed certificate certificate and client key files" + openssl req -x509 \ + -nodes \ + -days 365 \ + -newkey rsa:4096 \ + -keyout certs/${{ inputs.registry-server }}/client.key \ + -out certs/${{ inputs.registry-server }}/client.crt \ + -config req.cnf \ + -sha256 + + - name: Add the certificate to the system trust store + shell: bash + run: | + sudo apt install ca-certificates + sudo cp $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}/client.crt /usr/local/share/ca-certificates/${{ inputs.registry-server }}.crt + sudo cp $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}/client.crt /usr/local/share/ca-certificates/${{ inputs.registry-name }}.crt + sudo update-ca-certificates + + - name: Create local Docker registry + shell: bash + run: | + if [ "$(docker inspect -f '{{.State.Running}}' "${{ inputs.registry-name }}" 2>/dev/null || true)" != 'true' ]; then + echo "==== Creating a docker registry" + + docker run -d \ + -p ${{ inputs.registry-port }}:5000 \ + --restart=always \ + --name ${{ inputs.registry-name }} \ + -v $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}:/certs \ + -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/client.crt \ + -e REGISTRY_HTTP_TLS_KEY=/certs/client.key \ + registry:2 diff --git a/.github/actions/create-local-registry/secure/action.yaml b/.github/actions/create-local-registry/secure/action.yaml new file mode 100644 index 00000000000..5bace3a2f3b --- /dev/null +++ b/.github/actions/create-local-registry/secure/action.yaml @@ -0,0 +1,94 @@ +name: "Create a secure local registry" +description: | + This action creates a local registry for the images to be pushed to. + It uses the `docker` CLI to create a registry container and then starts it. + The registry is then available at `localhost:5000` by default. +inputs: + registry-name: + description: "The name of the local registry" + required: true + default: "radius-registry" + registry-server: + description: "The server name for the local registry" + required: true + default: "localhost" + registry-port: + description: "The port for the local registry" + required: true + default: "5000" +runs: + using: "composite" + steps: + - name: Create certificates for local registry + shell: bash + run: | + create_openssl_cfg() { + CFG=$( + cat <<'EOF' + [req] + distinguished_name = subject + x509_extensions = x509_ext + prompt = no + + [subject] + CN = localhost + + [x509_ext] + basicConstraints = critical, CA:TRUE + subjectKeyIdentifier = hash + authorityKeyIdentifier = keyid:always, issuer:always + keyUsage = critical, cRLSign, digitalSignature, keyCertSign + nsComment = "OpenSSL Generated Certificate" + subjectAltName = @alt_names + + [alt_names] + DNS.1 = ${{ inputs.registry-name }} + DNS.2 = ${{ inputs.registry-server }} + EOF + ) + echo "$CFG" + } + + # Create a temporary directory to store the certificates + temp_cert_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'temp_cert_dir') + echo "TEMP_CERT_DIR=$temp_cert_dir" >> $GITHUB_ENV + + pushd $temp_cert_dir + # Create the directory for the certificates + mkdir -p certs/${{ inputs.registry-server }} + + echo "==== Generate the openssl config" + create_openssl_cfg >req.cnf + + echo "==== Create the self signed certificate certificate and client key files" + openssl req -x509 \ + -nodes \ + -days 365 \ + -newkey rsa:4096 \ + -keyout certs/${{ inputs.registry-server }}/client.key \ + -out certs/${{ inputs.registry-server }}/client.crt \ + -config req.cnf \ + -sha256 + + - name: Add the certificate to the system trust store + shell: bash + run: | + sudo apt install ca-certificates + sudo cp $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}/client.crt /usr/local/share/ca-certificates/${{ inputs.registry-server }}.crt + sudo cp $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}/client.crt /usr/local/share/ca-certificates/${{ inputs.registry-name }}.crt + sudo update-ca-certificates + + - name: Create local Docker registry + shell: bash + run: | + if [ "$(docker inspect -f '{{.State.Running}}' "${{ inputs.registry-name }}" 2>/dev/null || true)" != 'true' ]; then + echo "==== Creating a docker registry" + + docker run -d \ + -p ${{ inputs.registry-port }}:5000 \ + --restart=always \ + --name ${{ inputs.registry-name }} \ + -v $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}:/certs \ + -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/client.crt \ + -e REGISTRY_HTTP_TLS_KEY=/certs/client.key \ + registry:2 diff --git a/.github/actions/save-pr-as-artifact/action.yaml b/.github/actions/save-pr-as-artifact/action.yaml index 10d58f1eba3..10ba355d727 100644 --- a/.github/actions/save-pr-as-artifact/action.yaml +++ b/.github/actions/save-pr-as-artifact/action.yaml @@ -8,10 +8,9 @@ runs: env: PR_NUMBER: ${{ github.event.number }} run: | - mkdir -p ./pr - echo $PR_NUMBER > ./pr/pr_number + mkdir -p ./pr + echo $PR_NUMBER > ./pr/pr_number - uses: actions/upload-artifact@v4 with: name: pr_number path: pr/ - diff --git a/.github/actions/setup-rad-cli/action.yaml b/.github/actions/setup-rad-cli/action.yaml index bc6e20a957a..1f1054acd5c 100644 --- a/.github/actions/setup-rad-cli/action.yaml +++ b/.github/actions/setup-rad-cli/action.yaml @@ -35,4 +35,3 @@ runs: shell: bash run: chmod +x rad working-directory: dist - diff --git a/.github/scripts/publish-recipes.sh b/.github/scripts/publish-recipes.sh index c839334b0d3..c065f911eac 100755 --- a/.github/scripts/publish-recipes.sh +++ b/.github/scripts/publish-recipes.sh @@ -64,13 +64,5 @@ for RECIPE in $(find "$DIRECTORY" -type f -name "*.bicep"); do echo "Publishing $RECIPE to $PUBLISH_REF" echo "- $PUBLISH_REF" >>$GITHUB_STEP_SUMMARY - - # Check if INSECURE_REGISTRY is set. If it is, we'll use the --plain-http flag when - # publishing the recipe. - if [[ -n "$INSECURE_REGISTRY" ]]; then - echo "INSECURE_REGISTRY is set. Using --plain-http flag." - rad bicep publish --file $RECIPE --target "br:$PUBLISH_REF" --plain-http - else - rad bicep publish --file $RECIPE --target "br:$PUBLISH_REF" - fi + rad bicep publish --file $RECIPE --target "br:$PUBLISH_REF" done diff --git a/.github/workflows/functional-test-noncloud.yaml b/.github/workflows/functional-test-noncloud.yaml index 63d6fb8fdb8..35114d5a849 100644 --- a/.github/workflows/functional-test-noncloud.yaml +++ b/.github/workflows/functional-test-noncloud.yaml @@ -47,9 +47,9 @@ on: env: # Go version - GOVER: "1.22.2" + GOVER: "1.22.5" # Helm version - HELM_VER: "v3.12.0" + HELM_VER: "v3.15.3" # KinD cluster version KIND_VER: "v0.23.0" # Dapr version @@ -57,16 +57,7 @@ env: # Dapr dashboard version DAPR_DASHBOARD_VER: "0.14.0" # Kubectl version - KUBECTL_VER: "v1.25.0" - - # Container registry for storing container images - CONTAINER_REGISTRY: "radius-registry:5000" - # Container registry for storing Bicep recipe artifacts - BICEP_RECIPE_REGISTRY: "radius-registry:5000" - # Local Docker registry name - LOCAL_REGISTRY_NAME: "radius-registry" - # Local Docker registry port - LOCAL_REGISTRY_PORT: "5000" + KUBECTL_VER: "v1.30.0" # The radius functional test timeout FUNCTIONALTEST_TIMEOUT: 15m @@ -84,6 +75,13 @@ env: # The number of failed tests to report. ISSUE_CREATE_THRESHOLD: 2 + # Local Docker registry name + LOCAL_REGISTRY_NAME: "radius-registry" + # Local Docker registry server + LOCAL_REGISTRY_SERVER: "localhost" + # Local Docker registry port + LOCAL_REGISTRY_PORT: "5000" + jobs: build: name: Build Radius for test @@ -140,9 +138,9 @@ jobs: name: Run ${{ matrix.name }} functional tests needs: build strategy: - fail-fast: false + fail-fast: true matrix: - os: [ubuntu-latest] + os: [ubuntu-latest-m] name: [ cli-noncloud, @@ -208,37 +206,18 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - name: Create local Docker registry - run: | - # This is going to start an insecure registry on localhost:5000 on the host machine. - if [ "$(docker inspect -f '{{.State.Running}}' "${{ env.LOCAL_REGISTRY_NAME }}" 2>/dev/null || true)" != 'true' ]; then - docker run \ - -d --restart=always -p "127.0.0.1:${{ env.LOCAL_REGISTRY_PORT }}:5000" --network bridge --name "${{ env.LOCAL_REGISTRY_NAME }}" \ - registry:2 - fi - - - name: Add insecure registry to Docker daemon - run: | - # Check if /etc/docker/daemon.json exists - if [ ! -f /etc/docker/daemon.json ]; then - echo "daemon.json doesn't exist. Creating one..." - echo '{}' | sudo tee /etc/docker/daemon.json - fi - - # Add insecure registries to /etc/docker/daemon.json - echo '{"insecure-registries": ["radius-registry:5000"]}' | sudo tee /etc/docker/daemon.json - sudo systemctl daemon-reload - sudo systemctl restart docker - - - name: Add radius-registry to /etc/hosts - run: | - sudo sh -c 'echo "127.0.0.1 radius-registry" >> /etc/hosts' + - name: Create a secure local registry + uses: ./.github/actions/create-local-registry/secure + with: + registry-name: ${{ env.LOCAL_REGISTRY_NAME }} + registry-server: ${{ env.LOCAL_REGISTRY_SERVER }} + registry-port: ${{ env.LOCAL_REGISTRY_PORT }} - name: Build and Push container images run: | make build && make docker-build && make docker-push env: - DOCKER_REGISTRY: ${{ env.CONTAINER_REGISTRY }} + DOCKER_REGISTRY: "${{ env.LOCAL_REGISTRY_SERVER }}:${{ env.LOCAL_REGISTRY_PORT }}" DOCKER_TAG_VERSION: ${{ env.REL_VERSION }} - name: Install rad CLI @@ -261,17 +240,17 @@ jobs: chmod +x ./kind # Create kind cluster with containerd registry config dir enabled - cat <