From 5655357e76c3bc7896366f736d1907dbea9e3e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lancelot=20de=20Ferri=C3=A8re?= Date: Wed, 15 Dec 2021 19:15:20 +0100 Subject: [PATCH] Update for testing env --- .github/workflows/deploy-test.yml | 55 +++++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 2 +- infra/deploy.sh | 4 ++- infra/{ => k8s}/deploy.yaml | 2 +- infra/{ => k8s}/ingress.yaml | 10 ++---- infra/{ => k8s}/service.yaml | 0 infra/render.sh | 7 ++-- infra/schema.yaml | 6 +++- infra/vals-prod.yaml | 10 ++++++ infra/vals-test.yaml | 10 ++++++ 10 files changed, 92 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/deploy-test.yml rename infra/{ => k8s}/deploy.yaml (91%) rename infra/{ => k8s}/ingress.yaml (76%) rename infra/{ => k8s}/service.yaml (100%) create mode 100644 infra/vals-prod.yaml create mode 100644 infra/vals-test.yaml diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml new file mode 100644 index 00000000..4fe29252 --- /dev/null +++ b/.github/workflows/deploy-test.yml @@ -0,0 +1,55 @@ +name: deploy-test +on: + push: +env: + GKE_CLUSTER: sltech-briq-k8s-cluster + GKE_ZONE: europe-west3-c + +jobs: + deploy: + name: "Deploy to test env" + environment: production + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + # Setup gcloud CLI + - uses: google-github-actions/setup-gcloud@master + with: + project_id: ${{ secrets.GCP_PROJECT_ID }} + service_account_key: ${{ secrets.GCP_SA_KEY }} + + # Configure Docker to use the gcloud command-line tool as a credential helper for authentication + - run: |- + gcloud auth configure-docker europe-west3-docker.pkg.dev + + # Get the GKE credentials + - uses: google-github-actions/get-gke-credentials@main + with: + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.GKE_ZONE }} + credentials: ${{ secrets.GCP_SA_KEY }} + + - uses: actions/setup-node@v2 + with: + node-version: '16' + cache: 'npm' + + - run: npm ci --include=dev + + - name: Install ytt + run: |- + # Taken from install script. + binary_type=linux-amd64 + ytt_version=v0.37.0 + ytt_checksum=1aad12386f6bae1a78197acdc7ec9e60c441f82c4ca944df8d3c78625750fe59 + wget -nv -O- https://github.com/vmware-tanzu/carvel-ytt/releases/download/${ytt_version}/ytt-${binary_type} > ytt + echo "${ytt_checksum} ytt" | shasum -c - + chmod +x ytt + sudo ln -s "$(pwd)/ytt" /usr/local/bin/ytt + ytt --version + + - name: Deploy + run: |- + K8S_ENV=test infra/deploy.sh diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 388da9b6..73f60013 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -54,4 +54,4 @@ jobs: - name: Deploy run: |- - infra/deploy.sh + K8S_ENV=prod infra/deploy.sh diff --git a/infra/deploy.sh b/infra/deploy.sh index 6424b2ec..c058b8c2 100755 --- a/infra/deploy.sh +++ b/infra/deploy.sh @@ -5,6 +5,8 @@ set -e #exit 0 export TAG=${TAG:=$(git rev-parse HEAD)} +export K8S_ENV=${K8S_ENV:="test"} + infra/run-docker.sh infra/render.sh -kubectl apply -f infra/dist/manifests.yaml --validate=true +kubectl apply -f infra/dist/manifests-${K8S_ENV}.yaml --validate=true diff --git a/infra/deploy.yaml b/infra/k8s/deploy.yaml similarity index 91% rename from infra/deploy.yaml rename to infra/k8s/deploy.yaml index d1bfcc76..592bd879 100644 --- a/infra/deploy.yaml +++ b/infra/k8s/deploy.yaml @@ -15,7 +15,7 @@ spec: spec: containers: - name: #@ data.values.name - image: #@ "europe-west3-docker.pkg.dev/healthy-saga-329513/sltech-briq/" + data.values.name + ":" + data.values.image_tag + image: #@ "europe-west3-docker.pkg.dev/healthy-saga-329513/sltech-briq/" + data.values.image_name + ":" + data.values.image_tag ports: - containerPort: 80 resources: diff --git a/infra/ingress.yaml b/infra/k8s/ingress.yaml similarity index 76% rename from infra/ingress.yaml rename to infra/k8s/ingress.yaml index 29b425ee..d541ff04 100644 --- a/infra/ingress.yaml +++ b/infra/k8s/ingress.yaml @@ -6,12 +6,12 @@ metadata: name: #@ data.values.name labels: #@ data.values.defaultLabels annotations: - kubernetes.io/ingress.global-static-ip-name: lb-sltech-company-ipv4-2 + kubernetes.io/ingress.global-static-ip-name: #@ data.values.static_ip networking.gke.io/v1beta1.FrontendConfig: #@ data.values.name networking.gke.io/managed-certificates: #@ data.values.name + "-managed-cert" spec: rules: -#@ arr = ["sltech.company", "www.sltech.company", "briq.construction", "www.briq.construction"] +#@ arr = data.values.sites #@ for i in arr: - host: #@ i http: @@ -40,8 +40,4 @@ kind: ManagedCertificate metadata: name: #@ data.values.name + "-managed-cert" spec: - domains: - - sltech.company - - www.sltech.company - - briq.construction - - www.briq.construction + domains: #@ data.values.sites diff --git a/infra/service.yaml b/infra/k8s/service.yaml similarity index 100% rename from infra/service.yaml rename to infra/k8s/service.yaml diff --git a/infra/render.sh b/infra/render.sh index 9d6ea84b..bb7d986f 100755 --- a/infra/render.sh +++ b/infra/render.sh @@ -2,10 +2,11 @@ set -e TAG=${TAG:=$(git rev-parse HEAD)} +K8S_ENV=${K8S_ENV:="test"} mkdir -p infra/dist -ytt -f infra/schema.yaml -f infra/ --data-value "image_tag=$TAG" > infra/dist/manifests.yaml +ytt -f infra/schema.yaml -f infra/vals-${K8S_ENV}.yaml -f infra/k8s/ --data-value "image_tag=$TAG" > infra/dist/manifests-${K8S_ENV}.yaml echo "validating client-side" -kubectl apply -f infra/dist/manifests.yaml --validate=true --dry-run=client +kubectl apply -f infra/dist/manifests-${K8S_ENV}.yaml --validate=true --dry-run=client echo "validating server-side" -kubectl apply -f infra/dist/manifests.yaml --validate=true --dry-run=server +kubectl apply -f infra/dist/manifests-${K8S_ENV}.yaml --validate=true --dry-run=server diff --git a/infra/schema.yaml b/infra/schema.yaml index a14ef7cb..e008e725 100644 --- a/infra/schema.yaml +++ b/infra/schema.yaml @@ -1,8 +1,12 @@ #@data/values-schema --- name: briq-builder -image_tag: "" +env: test +static_ip: lb-sltech-company-ipv4-2 +sites: [""] #@schema/type any=True defaultLabels: appname: briq-builder env: test +image_name: briq-builder +image_tag: "" diff --git a/infra/vals-prod.yaml b/infra/vals-prod.yaml new file mode 100644 index 00000000..29fa9f0d --- /dev/null +++ b/infra/vals-prod.yaml @@ -0,0 +1,10 @@ +#@data/values +--- +name: briq-builder +env: prod +static_ip: lb-sltech-company-ipv4-2 +sites: ["www.briq.construction", "briq.construction", "www.sltech.company", "sltech.company"] +#@schema/type any=True +defaultLabels: + appname: briq-builder + env: prod diff --git a/infra/vals-test.yaml b/infra/vals-test.yaml new file mode 100644 index 00000000..7b785f44 --- /dev/null +++ b/infra/vals-test.yaml @@ -0,0 +1,10 @@ +#@data/values +--- +name: dev-briq-builder +env: test +static_ip: lb-sltech-company-ipv4-4 +sites: ["test.sltech.company"] +#@schema/type any=True +defaultLabels: + appname: dev-briq-builder + env: test