-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from Shreyas220/add-aom-workflow
- Loading branch information
Showing
1 changed file
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
name: Meshery Consul Pattern Components Generator | ||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
|
||
jobs: | ||
check_consul_version: | ||
name: Check Consul Version | ||
runs-on: ubuntu-latest | ||
outputs: | ||
NEW_CONSUL_VERSION: ${{ env.NEW_CONSUL_VERSION }} | ||
NEW_CONSUL_CHART_VERSION: ${{ env.NEW_CONSUL_CHART_VERSION }} | ||
EXISTS: ${{ env.EXISTS }} | ||
steps: | ||
- name: Setup Helm | ||
id: sh | ||
uses: azure/setup-helm@v1 | ||
|
||
# retrieves consul version from helm charts | ||
- name: Get Consul Latest Release Metadata | ||
id: glrt | ||
run: | ||
helm repo add hashicorp https://helm.releases.hashicorp.com; | ||
helm repo update; | ||
RELEASE_METADATA=$(helm search repo hashicorp/consul --versions | sed -n 2p$'\n' | sed -e 's/\s/;/g' | tr -s ';'); | ||
echo "NEW_CONSUL_CHART_VERSION=`echo $RELEASE_METADATA | cut -d ';' -f2`" >> $GITHUB_ENV; | ||
echo "NEW_CONSUL_VERSION=`echo $RELEASE_METADATA | cut -d ';' -f3`" >> $GITHUB_ENV; | ||
|
||
- name: Check out code | ||
uses: actions/checkout@master | ||
with: | ||
fetch-depth: 1 | ||
|
||
- name: Check if manifests for latest release exist | ||
run: | | ||
if [ -d templates/oam/workloads/${{ env.NEW_CONSUL_VERSION }} ] | ||
then | ||
echo "EXISTS=true" >> $GITHUB_ENV | ||
else | ||
export "EXISTS=false" >> $GITHUB_ENV | ||
fi | ||
generator: | ||
name: Generate and push OAM definitions | ||
needs: [ check_consul_version ] | ||
if: ${{ !needs.check_consul_version.outputs.EXISTS }} | ||
env: | ||
NEW_CONSUL_VERSION: ${{ needs.check_consul_version.outputs.NEW_CONSUL_VERSION }} | ||
NEW_CONSUL_CHART_VERSION: ${{ needs.check_consul_version.outputs.NEW_CONSUL_CHART_VERSION }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@master | ||
with: | ||
fetch-depth: 1 | ||
token: ${{secrets.GH_ACCESS_TOKEN}} | ||
|
||
- name: Get Consul manifests | ||
run: | | ||
mkdir ./consul-crds | ||
cd ./consul-crds | ||
curl --silent --remote-name-all `curl --silent -H "Accept: application/vnd.github.VERSION.raw" https://api.github.com/repos/hashicorp/consul-k8s/contents/control-plane/config/crd/bases\?ref\=$(printf v%s $NEW_CONSUL_CHART_VERSION) | jq 'map(.download_url) | .[]' | tr -d '"'`; | ||
cd .. | ||
awk 'FNR==1 && NR>1 { printf("\n%s\n\n","---") } 1' consul-crds/*.yaml > ~/consul.yaml | ||
- name: Build jsonschema util | ||
run: | | ||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash | ||
export NVM_DIR="$HOME/.nvm" | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | ||
nvm install v14.15.3 | ||
nvm install-latest-npm | ||
git clone https://github.com/layer5io/kubeopenapi-jsonschema util | ||
cd util | ||
npm i; npm i nexe -g | ||
make linux | ||
- name: Generate Workload definitions | ||
run: | | ||
dirPath=../templates/oam/workloads/$NEW_CONSUL_VERSION | ||
cd util | ||
mkdir -p $dirPath | ||
meshName=Consul | ||
smpMeshName=CONSUL | ||
template='{"apiVersion":"core.oam.dev/v1alpha1","kind":"WorkloadDefinition","metadata":{},"spec":{"definitionRef":{},"metadata":{"@type":"pattern.meshery.io/mesh/workload","meshVersion":"'v$NEW_CONSUL_VERSION'","meshName":"'$smpMeshName'","k8sAPIVersion":null,"k8sKind":""}}}' | ||
crds=$(./kubeopenapi-jsonschema --location ~/consul.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition")]' -o json --o-filter '$..["spec"]["names"]["kind"]' | jq '.[]') | ||
for t in ${crds[@]}; do | ||
nameUpper=`echo $t | tr -d '"'` | ||
nameLower=`echo $t | tr -d '"' | tr '[:upper:]' '[:lower:]'` | ||
definitionRef=$(printf %s.consul.meshery.layer5.io $nameLower) | ||
apiVersion=$(./kubeopenapi-jsonschema --location ~/consul.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..spec.versions[0]' --o-filter "$[].name" -o json | jq '.[]' | tr -d '"') | ||
apiGroup=$(./kubeopenapi-jsonschema --location ~/consul.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..spec' --o-filter "$[].group" -o json | jq '.[]' | tr -d '"') | ||
./kubeopenapi-jsonschema --location ~/consul.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..openAPIV3Schema.properties.spec' --o-filter "$[]" -o json |\ | ||
jq '.[]' > $dirPath/$nameLower.consul.meshery.layer5io.schema.json | ||
echo $template |\ | ||
jq ' | ||
."metadata"."name" = "'$(printf %s.Consul $nameUpper)'" | ||
| ."spec"."metadata"."k8sAPIVersion" = "'$(printf $apiGroup/$apiVersion $apiGroup $apiVersion)'" | ||
| ."spec"."metadata"."k8sKind" = "'$nameUpper'" | ||
| ."spec"."definitionRef"."name"="'$definitionRef'"' > $dirPath/$nameLower.consul_definition.json | ||
done | ||
- name: Cleanup | ||
run: | | ||
rm -rf util | ||
- name: Commit changes | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
file_pattern: templates/ | ||
commit_user_name: l5io | ||
commit_user_email: [email protected] | ||
commit_author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> | ||
commit_options: '--signoff' | ||
commit_message: "[Patterns] Pattern components generated from latest Consul manifests" | ||
branch: master |