Skip to content

Commit

Permalink
Added website backend workflow and virtualServerRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
Psalmz777 committed Nov 26, 2024
1 parent be43969 commit 0e037c8
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 3 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/deploy-apis-to-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
run_workflows: ${{ steps.check_files.outputs.run_workflows }} # workflows
run_incentives: ${{ steps.check_files.outputs.run_incentives }} # incentives
run_spatial: ${{ steps.check_files.outputs.run_spatial }} # spatial
run_website: ${{ steps.check_files.outputs.run_website }} # website
run_kafka_connectors: ${{ steps.check_files.outputs.run_kafka_connectors }} # kafka connectors
run_nginx: ${{ steps.check_files.outputs.run_nginx }} # nginx

Expand Down Expand Up @@ -98,6 +99,7 @@ jobs:
echo "run_incentives=false" >>$GITHUB_OUTPUT
echo "run_insights=false" >>$GITHUB_OUTPUT
echo "run_spatial=false" >>$GITHUB_OUTPUT
echo "run_website=false" >>$GITHUB_OUTPUT
echo "run_kafka_connectors=false" >>$GITHUB_OUTPUT
echo "run_nginx=false" >>$GITHUB_OUTPUT
Expand Down Expand Up @@ -263,13 +265,22 @@ jobs:
if [[ $file == k8s/insights/* ]]; then
echo "run_insights=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/spatial/* ]]; then
echo "run_spatial=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/spatial/* ]]; then
echo "run_spatial=true" >>$GITHUB_OUTPUT
fi
if [[ $file == src/website/* ]]; then
echo "run_website=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/website/* ]]; then
echo "run_website=true" >>$GITHUB_OUTPUT
fi
if [[ $file == k8s/nginx/production/* ]]; then
echo "run_nginx=true" >>$GITHUB_OUTPUT
Expand All @@ -293,6 +304,7 @@ jobs:
echo "run_incentives=true" >>$GITHUB_OUTPUT
echo "run_insights=true" >>$GITHUB_OUTPUT
echo "run_spatial=true" >>$GITHUB_OUTPUT
echo "run_website=true" >>$GITHUB_OUTPUT
echo "run_view=true" >>$GITHUB_OUTPUT
echo "run_kafka_connectors=true" >>$GITHUB_OUTPUT
echo "run_nginx=true" >>$GITHUB_OUTPUT
Expand Down Expand Up @@ -1732,3 +1744,62 @@ jobs:
kubectl create configmap --dry-run=client -o yaml --from-env-file=.env prod-spatial-api-config | kubectl replace -f - -n production
gcloud secrets versions access latest --secret="prod-key-device-monitoring-service-account" > google_application_credentials.json
kubectl create configmap --dry-run=client -o yaml --from-file=google_application_credentials.json prod-spatial-api-config-files | kubectl replace -f - -n production
### website ###
website:
name: build-push-deploy-website
needs: [check, image-tag]
if: needs.check.outputs.run_website == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]

- name: Login to GCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: _json_key
password: ${{ secrets.GCR_CONFIG }}

- name: Login to K8S
uses: azure/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG_PROD }}

- name: Build and Push Docker Image
run: |
cd src/website/
docker build --tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-website-api:${{ needs.image-tag.outputs.build_id }} .
docker tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-website-api:${{ needs.image-tag.outputs.build_id }} ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-website-api:latest
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-website-api:${{ needs.image-tag.outputs.build_id }}
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/airqo-website-api:latest
- name: Update corresponding helm values file(with retry)
uses: Wandalen/[email protected] # Retries action on fail
with:
action: fjogeleit/yaml-update-action@main # Action to retry
with: |
valueFile: "k8s/website/values-prod.yaml"
propertyPath: "image.tag"
value: ${{ needs.image-tag.outputs.build_id }}
branch: ${{ env.DEPLOY_BRANCH }}
token: ${{ secrets.YAML_UPDATER_TOKEN }}
message: "Update website production image tag to ${{ needs.image-tag.outputs.build_id }}"
- name: Login to GCP
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GCP_SA_CREDENTIALS }}

- name: Setup Cloud SDK
uses: google-github-actions/[email protected]

- name: Update the corresponding k8s configmap(s)
run: |
cd src/website/
gcloud secrets versions access latest --secret="prod-env-website-backend" > .env
kubectl create configmap --dry-run=client -o yaml --from-env-file=.env prod-website-api-config | kubectl replace -f - -n production
gcloud secrets versions access latest --secret="prod-key-device-monitoring-service-account" > google_application_credentials.json
kubectl create configmap --dry-run=client -o yaml --from-file=google_application_credentials.json prod-website-api-config-files | kubectl replace -f - -n production
25 changes: 22 additions & 3 deletions k8s/nginx/production/platform-vs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
name: argocd
namespace: cicd
namespace: argocd
spec:
host: platform.airqo.net
upstreams:
Expand Down Expand Up @@ -53,6 +53,23 @@ spec:
action:
pass: inventory

---
apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
name: website
namespace: production
spec:
host: platform.airqo.net
upstreams:
- name: website
service: airqo-website-api-svc
port: 8000
subroutes:
- path: /website
action:
pass: website

---
apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
Expand Down Expand Up @@ -139,11 +156,13 @@ spec:
- path: /workflows
route: pipeline/workflows
- path: /argocd
route: cicd/argocd
route: argocd/argocd
- path: /inventory
route: production/inventory
- path: /reports
route: production/reports
route: production/reports
- path: /website
route: production/website
- path: ~ /api\/v[1-2]\/users
action:
proxy:
Expand Down

0 comments on commit 0e037c8

Please sign in to comment.