create argocd echo app #10
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: 'Copied Repo Name' | |
type: string | |
default: 'echo-app' | |
cluster-name: | |
description: 'Name of GKE cluster to create app on' | |
default: "demo-cluster" | |
gcp-region: | |
type: choice | |
description: 'GCP region of cluster' | |
default: "us-east5" | |
options: | |
- us-east5 | |
- us-central1 | |
- us-east4 | |
gcp-zone: | |
type: choice | |
description: 'GCP zone of 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":"json","insecure_ssl":"0"}}' | gh api repos/km-demos/$REPO_NAME/hooks --input - -X POST | |
curl -X PUT \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $GITHUB_TOKEN"\ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/km-demos/$REPO_NAME/branches/main/protection \ | |
-d '{"required_status_checks":null,"enforce_admins":false,"required_pull_request_reviews":{"required_approving_review_count": 0},"restrictions":null}' | |
- 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: | | |
kubectl create ns $REPO_NAME | |
kubectl create secret docker-registry ghcr-login-secret -n $REPO_NAME --docker-server=https://ghcr.io \ | |
--docker-username=km-demos --docker-password=${{ secrets.KM_MANAGE_PACKAGES_TOKEN }} [email protected] | |
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 | |