Skip to content

Commit

Permalink
Improve upstream version checks and perform misc housekeeping (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
amacnair authored Mar 18, 2024
1 parent 72284ee commit c722528
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 17 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/release-and-pr-kubernetes-ingress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
outputs:
value: ${{ steps.tag.outputs.NO_CHANGE }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_API_TOKEN }}
Expand All @@ -28,13 +28,11 @@ jobs:
env:
REPO: signalsciences/sigsci-nginx-ingress-controller
run: |
INGRESS_LATEST=$(curl -sL https://api.github.com/repos/kubernetes/ingress-nginx/releases | grep "tag_name" | grep -m1 "controller" | cut -d '"' -f4 | cut -d 'v' -f2)
SIGSCI_LATEST=$(curl -sL ${{ env.GH_REPO }}/releases | grep "tag_name" | grep -m1 "tag_name" | cut -d '"' -f4)
INGRESS_LATEST=$(./scripts/latest-version.sh upstream)
SIGSCI_LATEST=$(./scripts/latest-version.sh sigsci)
version() { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; }
if [ $(version $INGRESS_LATEST) -eq $(version $SIGSCI_LATEST) ]; then
echo "ingress-nginx version: $INGRESS_LATEST -- matches sigsci version: $SIGSCI_LATEST"
if [ "$INGRESS_LATEST" == "$SIGSCI_LATEST" ]; then
echo "ingress-nginx version: $INGRESS_LATEST matches sigsci version: $SIGSCI_LATEST"
echo "::set-output name=NO_CHANGE::true"
else
TAG=$INGRESS_LATEST
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG NGINX_INGRESS_VERSION=${NGINX_INGRESS_VERSION:-v0.47.0}
FROM --platform=$BUILDPLATFORM k8s.gcr.io/ingress-nginx/controller:${NGINX_INGRESS_VERSION}
ARG NGINX_INGRESS_VERSION=${NGINX_INGRESS_VERSION:-v1.10.0}
FROM --platform=$BUILDPLATFORM registry.k8s.io/ingress-nginx/controller:${NGINX_INGRESS_VERSION}

ARG BUILDPLATFORM
ARG PKGNAME=${PKGNAME:-nginx-module-sigsci-nxo}
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ Prebuilt images hosted here: https://hub.docker.com/repository/docker/signalscie

Tags/Releases track image tags of the upstream docker repo.
These images work as drop-in replacements for:
* `k8s.gcr.io/ingress-nginx/controller` images with corresponding tags (0.43.0)
* `quay.io/kubernetes-ingress-controller/nginx-ingress-controller` images with corresponding tags (0.25.0-0.33.0)
* `registry.k8s.io/ingress-nginx/controller` images with corresponding tags

***NGINX, Inc.***
Use `Dockerfile.nginxinc` if you want to add the Signal Sciences NGINX module into the stock nginxinc/kubernetes-ingress image (https://github.com/nginxinc/kubernetes-ingress)

Prebuilt images are hosted here: https://hub.docker.com/repository/docker/signalsciences/sigsci-nginxinc-ingress-controller

Tags/Releases are also used to track the tags of the upstream repo:
* `nginx/nginx-ingress` images with corresponding tags (>= 2.2.0)

## Helm install instructions with override file

The following are steps to install [kubernetes/ingress-nginx](https://github.com/kubernetes/ingress-nginx) via helm using the sigsci-values.yaml override file. This adds the custom sigsci-nginx-ingress-controller and sigsci-agent.
Expand Down Expand Up @@ -111,7 +108,7 @@ controller:
# Replaces the default nginx-controller image with a custom image that contains the Signal Sciences nginx Module
image:
repository: signalsciences/sigsci-nginx-ingress-controller
tag: "0.47.0"
tag: "1.10.0"
pullPolicy: IfNotPresent
```

Expand Down
63 changes: 63 additions & 0 deletions scripts/latest-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# What should we output the latest version of: sigsci or upstream?
TARGET="${1:-upstream}"

GH_REPO="${GH_REPO:-https://api.github.com/repos/signalsciences/sigsci-nginx-ingress-controller}"

# Regex to restict to subset of semver tags (no pre-release versions)
VERSION_REGEX="v[0-9]+\.[0-9]+\.[0-9]+$"
CONTROLLER_REGEX="controller-${VERSION_REGEX}"


# Print out latest upstream controller version as bare version (1.2.3)
function outputLatestKubernetesUpstream () {
# Grab list of full controller releases without any -alpha, -beta, -RC etc semver suffixes
ingress_controller_tags=$(curl -sL https://api.github.com/repos/kubernetes/ingress-nginx/releases\?per_page\=100 | jq -r '.[] | select( .tag_name | contains("controller")) | .tag_name' | grep -E "$CONTROLLER_REGEX")

# Clean up the tags to be plain version numbers (1.2.3) and sort them in a version aware manner
sorted_ingress_versions=$(echo "$ingress_controller_tags" | cut -d '-' -f2 | cut -d 'v' -f2 | sort --field-separator=. --key=1,1n --key=2,2n --key=3,3n)

# Grab just the latest version and output
echo "$sorted_ingress_versions" | tail -n1
}

# Print out latest NGINX Inc upstream controller version as bare version (1.2.3)
function outputLatestNginxIncUpstream() {
# Grab list of nginx inc controller releases without any -alpha, -beta, -RC etc semver suffixes
ingress_inc_controller_tags=$(curl -sL https://api.github.com/repos/nginxinc/kubernetes-ingress/releases\?per_page\=100 | jq -r '.[].tag_name' | grep -E "$VERSION_REGEX")

# Clean up the tags to be plain version numbers (1.2.3) and sort them in a version aware manner
sorted_ingress_inc_versions=$(echo "$ingress_inc_controller_tags" | cut -d '-' -f2 | cut -d 'v' -f2 | sort --field-separator=. --key=1,1n --key=2,2n --key=3,3n)

# Grab just the latest version and output
echo "$sorted_ingress_inc_versions" | tail -n1
}

# Print out the latest sigsci controller version as a bare version (1.2.3)
function outputLatestSigsciVersion () {
# Grab list of sigsci controller versions
sigsci_tags=$(curl -sL ${GH_REPO}/releases\?per_page\=100 | jq -r '.[].tag_name')

# Sort the tags in a version aware manner
sorted_sigsci_tags=$(echo "$sigsci_tags" | sort --field-separator=. --key=1,1n --key=2,2n --key=3,3n)

# Grab just the latest verison and output
echo "$sorted_sigsci_tags" | tail -n1
}

case "$TARGET" in
upstream)
outputLatestKubernetesUpstream
;;
nginxinc)
outputLatestNginxIncUpstream
;;
sigsci | fastly)
outputLatestSigsciVersion
;;
*)
echo "Unknown target argument: specify 'upstream', 'sigsci' or 'nginxinc'"
exit 1
;;
esac
2 changes: 1 addition & 1 deletion sigsci-nginxinc-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ controller:
image:
## Replaces the default nginx-controller image with a custom image that contains the Signal Sciences nginx Module
repository: signalsciences/sigsci-nginxinc-ingress-controller
tag: "2.2.0"
tag: "2.3.0"
pullPolicy: IfNotPresent

# Load module and set sigsci_agent_host
Expand Down

0 comments on commit c722528

Please sign in to comment.