Skip to content

Commit

Permalink
simplify release workflow (#2251)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdn5126 authored Feb 7, 2023
1 parent d2f240d commit 4dac30b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 226 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: VPC CNI Release

on: [push, workflow_dispatch]
on:
release:
types: [published]

permissions:
contents: read
Expand All @@ -11,17 +13,18 @@ env:

jobs:
release:
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout latest commit in the PR
uses: actions/checkout@v3
with:
ref: "refs/tags/{{ github.event.release.tag_name }}"
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.19"
- name: Attach release artifacts
run: make release
- name: Generate CNI YAML
run: make generate-cni-yaml
- name: Create eks-charts PR
run: make ekscharts-sync-release
- name: Create sample manifests PR
Expand Down
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,9 @@ ekscharts-sync-release:
${MAKEFILE_PATH}/scripts/sync-to-eks-charts.sh -b $$HELM_CHART_NAME -r ${REPO_FULL_NAME} -n -y ; \
done

upload-resources-to-github:
${MAKEFILE_PATH}/scripts/upload-resources-to-github.sh

generate-cni-yaml:
${MAKEFILE_PATH}/scripts/generate-cni-yaml.sh

release: generate-cni-yaml upload-resources-to-github

config-folder-sync:
${MAKEFILE_PATH}/scripts/sync-to-config-folder.sh

Expand Down
2 changes: 1 addition & 1 deletion charts/aws-vpc-cni/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ rules:
- apiGroups: [""]
resources:
- nodes
verbs: ["list", "watch", "get"]
verbs: ["list", "watch", "get", "update"]
- apiGroups: ["", "events.k8s.io"]
resources:
- events
Expand Down
41 changes: 6 additions & 35 deletions scripts/generate-cni-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ set -euo pipefail
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

PLATFORM=$(uname | tr '[:upper:]' '[:lower:]')
HELM_VERSION="3.6.3"
HELM_VERSION="3.11.0"
NAMESPACE="kube-system"

MAKEFILEPATH=$SCRIPTPATH/../Makefile
VERSION=$(make -s -f $MAKEFILEPATH version)
BUILD_DIR=$SCRIPTPATH/../build/cni-rel-yamls/$VERSION

REGIONS_FILE=$SCRIPTPATH/../charts/regions.json
INDV_RESOURCES_DIR=$BUILD_DIR/individual-resources
CNI_TAR_RESOURCES_FILE=$BUILD_DIR/cni_individual-resources.tar
METRICS_TAR_RESOURCES_FILE=$BUILD_DIR/cni_metrics_individual-resources.tar
CNI_RESOURCES_YAML=$BUILD_DIR/aws-k8s-cni
METRICS_RESOURCES_YAML=$BUILD_DIR/cni-metrics-helper

mkdir -p $INDV_RESOURCES_DIR

mkdir -p $BUILD_DIR

USAGE=$(cat << 'EOM'
Usage: generate-cni-yaml [-n <K8s_NAMESPACE>]
Expand Down Expand Up @@ -80,8 +76,8 @@ jq -c '.[]' $REGIONS_FILE | while read i; do
--set image.domain=$ecrDomain \
--namespace $NAMESPACE \
$SCRIPTPATH/../charts/aws-vpc-cni > $NEW_CNI_RESOURCES_YAML
cat $NEW_CNI_RESOURCES_YAML | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml
mv $BUILD_DIR/helm_annotations_removed.yaml $NEW_CNI_RESOURCES_YAML
# Remove 'managed-by: Helm' annotation
sed -i '/helm.sh\|app.kubernetes.io\/managed-by: Helm/d' $NEW_CNI_RESOURCES_YAML

$BUILD_DIR/helm template cni-metrics-helper \
--set image.region=$ecrRegion,\
Expand All @@ -90,37 +86,12 @@ jq -c '.[]' $REGIONS_FILE | while read i; do
--set image.tag=$VERSION,\
--namespace $NAMESPACE \
$SCRIPTPATH/../charts/cni-metrics-helper > $NEW_METRICS_RESOURCES_YAML
cat $NEW_METRICS_RESOURCES_YAML | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml
mv $BUILD_DIR/helm_annotations_removed.yaml $NEW_METRICS_RESOURCES_YAML
done

$BUILD_DIR/helm template --include-crds \
--namespace $NAMESPACE \
--output-dir $INDV_RESOURCES_DIR/ \
$SCRIPTPATH/../charts/aws-vpc-cni/

for i in $INDV_RESOURCES_DIR/aws-vpc-cni/templates/*; do
cat $i | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml
mv $BUILD_DIR/helm_annotations_removed.yaml $i
# Remove 'managed-by: Helm' annotation
sed -i '/helm.sh\|app.kubernetes.io\/managed-by: Helm/d' $NEW_METRICS_RESOURCES_YAML
done

$BUILD_DIR/helm template \
--namespace $NAMESPACE \
--output-dir $INDV_RESOURCES_DIR/ \
$SCRIPTPATH/../charts/cni-metrics-helper/

for i in $INDV_RESOURCES_DIR/cni-metrics-helper/templates/*; do
cat $i | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml
mv $BUILD_DIR/helm_annotations_removed.yaml $i
done


cd $INDV_RESOURCES_DIR/aws-vpc-cni/ && tar cvf $CNI_TAR_RESOURCES_FILE templates/*
cd $INDV_RESOURCES_DIR/cni-metrics-helper/ && tar cvf $METRICS_TAR_RESOURCES_FILE templates/*
cd $SCRIPTPATH

echo "Generated aws-vpc-cni and cni-metrics-helper manifest resources files in:"
echo " - $CNI_RESOURCES_YAML"
echo " - $METRICS_RESOURCES_YAML"
echo " - $CNI_TAR_RESOURCES_FILE"
echo " - $METRICS_TAR_RESOURCES_FILE"
58 changes: 9 additions & 49 deletions scripts/sync-to-config-folder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
set -euo pipefail
set +x


SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
BUILD_DIR="${SCRIPTPATH}/../build"

Expand All @@ -13,23 +12,21 @@ PR_ID=$(uuidgen | cut -d '-' -f1)

SYNC_DIR="${BUILD_DIR}/config-sync"

BINARY_BASE=""
BINARY_BASE="aws-vpc-cni"
INCLUDE_NOTES=0
MANUAL_VERIFY=1

GH_CLI_VERSION="0.10.1"
GH_CLI_VERSION="2.22.1"
GH_CLI_CONFIG_PATH="${HOME}/.config/gh/config.yml"
KERNEL=$(uname -s | tr '[:upper:]' '[:lower:]')
OS="${KERNEL}"
if [[ "${KERNEL}" == "darwin" ]]; then
OS="macOS"
fi

VERSION=$(make -s -f "${SCRIPTPATH}/../Makefile" version)

USAGE=$(cat << EOM
Usage: sync-to-config-folder -r <repo>
Updates config folder in master and release branch
Updates config folder in master branch
Example: sync-to-config-folder -r "${REPO}"
Optional:
-r Github repo to sync to in the form of "org/name" (i.e. -r "${REPO}")
Expand Down Expand Up @@ -63,6 +60,7 @@ fi

echo $REPO

# Install GitHub CLI
if [[ -z $(command -v gh) ]] || [[ ! $(gh --version) =~ $GH_CLI_VERSION ]]; then
mkdir -p "${BUILD_DIR}"/gh
curl -Lo "${BUILD_DIR}"/gh/gh.tar.gz "https://github.com/cli/cli/releases/download/v${GH_CLI_VERSION}/gh_${GH_CLI_VERSION}_${OS}_amd64.tar.gz"
Expand All @@ -78,6 +76,7 @@ function restore_gh_config() {
mv -f "${GH_CLI_CONFIG_PATH}.bkup" "${GH_CLI_CONFIG_PATH}" || :
}

# Set auth tokens for GitHub CLI
if [[ -n $(env | grep GITHUB_TOKEN) ]] && [[ -n "${GITHUB_TOKEN}" ]]; then
trap restore_gh_config EXIT INT TERM ERR
mkdir -p "${HOME}/.config/gh"
Expand Down Expand Up @@ -105,6 +104,7 @@ rm -rf "${SYNC_DIR}"
mkdir -p "${SYNC_DIR}"
cd "${SYNC_DIR}"

# Clone upstream repo and setup git parameters
gh repo clone aws/amazon-vpc-cni-k8s
DEFAULT_BRANCH=$(git rev-parse --abbrev-ref HEAD | tr -d '\n')

Expand All @@ -116,6 +116,7 @@ git remote set-url origin https://"${GITHUB_USERNAME}":"${GITHUB_TOKEN}"@github.
git config user.name "eks-networking-bot"
git config user.email "[email protected]"

# Fork master branch and create sync PR
FORK_RELEASE_BRANCH="${BINARY_BASE}-${VERSION}-${PR_ID}"
git checkout -b "${FORK_RELEASE_BRANCH}" origin/master

Expand All @@ -136,48 +137,7 @@ EOM
)

git push -u origin "${FORK_RELEASE_BRANCH}"
gh pr create --title "🥳 ${BINARY_BASE} ${VERSION} Automated manifest sync! 🥑" \
gh pr create --title "${BINARY_BASE} ${VERSION} Automated manifest sync! 🥑" \
--body "${PR_BODY}" --repo ${REPO}

echo "✅ Manifest folder PR created for master"

CLONE_DIR="${BUILD_DIR}/config-sync-release"
SYNC_DIR="$CLONE_DIR"
echo $SYNC_DIR
rm -rf "${SYNC_DIR}"
mkdir -p "${SYNC_DIR}"
cd "${SYNC_DIR}"
gh repo clone aws/amazon-vpc-cni-k8s
echo "Release branch $RELEASE_BRANCH"
CONFIG_DIR=amazon-vpc-cni-k8s/config/master
cd $CONFIG_DIR
REPO_NAME=$(echo ${REPO} | cut -d'/' -f2)
git remote set-url origin https://"${GITHUB_USERNAME}":"${GITHUB_TOKEN}"@github.com/"${GITHUB_USERNAME}"/"${REPO_NAME}".git

git config user.name "eks-networking-bot"
git config user.email "[email protected]"

FORK_RELEASE_BRANCH="${BINARY_BASE}-${VERSION}-${PR_ID}"
git checkout -b "${FORK_RELEASE_BRANCH}" origin/$RELEASE_BRANCH

cp $SCRIPTPATH/../build/cni-rel-yamls/${VERSION}/aws-k8s-cni*.yaml .
cp $SCRIPTPATH/../build/cni-rel-yamls/${VERSION}/cni-metrics-helper*.yaml .

git add --all
git commit -m "${BINARY_BASE}: ${VERSION}"

PR_BODY=$(cat << EOM
## ${BINARY_BASE} ${VERSION} Automated manifest folder Sync! 🤖🤖
### Description 📝
Updating all the generated release artifacts in master/config for $RELEASE_BRANCH branch.
EOM
)

git push -u origin "${FORK_RELEASE_BRANCH}":$RELEASE_BRANCH
gh pr create --title "🥳 ${BINARY_BASE} ${VERSION} Automated manifest sync! 🥑" \
--body "${PR_BODY}" --repo ${REPO} --base ${RELEASE_BRANCH}

echo "✅ Manifest folder PR created for $RELEASE_BRANCH"
echo "Manifest folder PR created for master"
5 changes: 2 additions & 3 deletions scripts/sync-to-eks-charts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BINARY_BASE=""
INCLUDE_NOTES=0
MANUAL_VERIFY=1

GH_CLI_VERSION="0.10.1"
GH_CLI_VERSION="2.22.1"
GH_CLI_CONFIG_PATH="${HOME}/.config/gh/config.yml"
KERNEL=$(uname -s | tr '[:upper:]' '[:lower:]')
OS="${KERNEL}"
Expand Down Expand Up @@ -130,7 +130,6 @@ cd "${FORK_DIR}"
git remote set-url origin https://"${GITHUB_USERNAME}":"${GITHUB_TOKEN}"@github.com/"${GITHUB_USERNAME}"/"${CHARTS_REPO_NAME}".git
DEFAULT_BRANCH=$(git rev-parse --abbrev-ref HEAD | tr -d '\n')


if diff -x ".*" -r "$HELM_CHART_DIR/" "${FORK_DIR}/stable/${HELM_CHART_NAME}/" &> /dev/null ; then
echo " ✅ Charts already in sync; no updates needed"
exit
Expand Down Expand Up @@ -194,4 +193,4 @@ fi
gh pr create --title "🥳 ${BINARY_BASE} ${VERSION} Automated Release! 🥑" \
--body "${PR_BODY}" --repo ${CHARTS_REPO}

echo "EKS charts sync complete"
echo "EKS charts sync complete!"
Loading

0 comments on commit 4dac30b

Please sign in to comment.