create argocd echo app #5
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
name: create argocd echo app | |
on: | |
workflow_dispatch: | |
inputs: | |
repo_name: | |
description: 'Copie Repo Name' | |
type: string | |
default: 'echo-app' | |
cluster-name: | |
description: 'Name of GKE cluster to create' | |
default: "demo-cluster" | |
gcp-region: | |
type: choice | |
description: 'GCP region to create cluster' | |
default: "us-east5" | |
options: | |
- us-east5 | |
- us-central1 | |
- us-east4 | |
gcp-zone: | |
type: choice | |
description: 'GCP zone to create cluster' | |
default: "a" | |
options: | |
- a | |
- b | |
- c | |
env: | |
REPO_NAME: ${{ github.event.inputs.repo_name || 'echo-app' }} | |
CLUSTER_NAME: ${{ github.event.inputs.cluster-name || 'demo-cluster' }} | |
GCP_REGION: ${{ github.event.inputs.gcp-region || 'us-east5' }} | |
GCP_ZONE: ${{ github.event.inputs.gcp-region || 'us-east5' }}-${{ github.event.inputs.gcp-zone || 'a' }} | |
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT }} | |
GCP_DNS_ZONE: examples-kurtmadel | |
jobs: | |
create-argocd-echo-app: | |
runs-on: ubuntu-22.04 | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
- name: Generate km-demos GitHub App token | |
id: generate_token | |
uses: tibdex/[email protected] | |
with: | |
app_id: ${{ secrets.KM_DEMOS_GITHUB_APP_ID }} | |
private_key: ${{ secrets.KM_DEMOS_GITHUB_APP_KEY }} | |
- name: create-echo-repo-from-template | |
shell: bash | |
env: | |
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} | |
run: | | |
gh api \ | |
--method POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/km-demos/echo-app-template/generate \ | |
-f owner='km-demos' \ | |
-f name="$REPO_NAME" \ | |
-f description='Simple ehco app to use with ArgoCD demo.' \ | |
-F include_all_branches=true \ | |
-F private=false | |
echo '{"name":"web","active":true,"events":["push","pull_request","release"],"config":{"url":"https://argocd.examples.kurtmadel.com/api/webhook","secret":"'"${{ secrets.ARGOCD_GITHUB_WEBHOOK_SECRET }}"'","content_type":"form","insecure_ssl":"0"}}' | gh api repos/km-demos/$REPO_NAME/hooks --input - -X POST | |
- id: 'gcp-auth' | |
name: 'Authenticate to Google Cloud' | |
uses: google-github-actions/[email protected] | |
with: | |
workload_identity_provider: ${{ secrets.WIF_POOL }} | |
service_account: ${{ secrets.SA_EMAIL }} | |
- id: get-credentials | |
uses: google-github-actions/[email protected] | |
with: | |
cluster_name: ${{ env.CLUSTER_NAME }} | |
location: ${{ env.GCP_ZONE }} | |
- id: create-dns-entry | |
run: | | |
INGRESS_IP=$(kubectl get services -n ingress-nginx | grep LoadBalancer | awk '{print $4}') | |
gcloud dns --project=$GCP_PROJECT_ID record-sets transaction start --zone=$GCP_DNS_ZONE | |
gcloud dns --project=$GCP_PROJECT_ID record-sets transaction add $INGRESS_IP --name=$REPO_NAME.examples.kurtmadel.com. --ttl=300 --type=A --zone=$GCP_DNS_ZONE | |
gcloud dns --project=$GCP_PROJECT_ID record-sets transaction execute --zone=$GCP_DNS_ZONE | |
- id: create-argocd-app | |
run: | | |
yq e -i ".metadata.name = \"$REPO_NAME\"" argo-cd/argocd-app.yaml | |
yq e -i ".spec.source.repoURL = \"https://github.com/km-demos/$REPO_NAME.git\"" argo-cd/argocd-app.yaml | |
yq e -i ".spec.destination.namespace = \"$REPO_NAME\"" argo-cd/argocd-app.yaml | |
kubectl apply -f argo-cd/argocd-app.yaml | |