added dev inner loop exp with devspace

This commit is contained in:
sushantdivate 2021-06-18 14:43:56 -07:00
Родитель 64ac74d8a0
Коммит b14f9a5a78
5 изменённых файлов: 141 добавлений и 0 удалений

7
.env.template Normal file
Просмотреть файл

@ -0,0 +1,7 @@
VOTE_APP_TITLE='Awesome Voting App'
AZURE_VOTE_IMAGE_REPO=<ACR_NAME>.azurecr.io/azvote
FRONTEND_IMAGE=v2
BACKEND_IMAGE=6.0.8
TARGET_NAMESPACE=local-dev
DEMO_APP_URL='/azvote-dev'
SYSTEM_LABEL='VOTE-APP'

7
.gitignore поставляемый
Просмотреть файл

@ -99,3 +99,10 @@ ENV/
# mypy
.mypy_cache/
# Ignore DevSpace cache and log folder
.devspace/
# Ignore generated manifest
manifests.yaml

32
INNER-LOOP.MD Normal file
Просмотреть файл

@ -0,0 +1,32 @@
## Developer Inner-Loop.
This document describes inner-loop flow while making changes to Azure Vote front-end and back-end application code.
### Prerequisite
- [DevSpace CLI](https://devspace.sh/cli/docs/getting-started/installation)
- [Install Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
- [Install Docker](https://docs.docker.com/get-docker/)
- [Install Kubectl](https://kubernetes.io/docs/tasks/tools/)
- [Create ACR token](https://docs.microsoft.com/en-us/cli/azure/acr/token?view=azure-cli-latest#az_acr_token_create)
- Login with `docker login -u <TOKEN_NAME> -p <TOKEN> <ACR_NAME>.azurecr.io`
This repository is using [DevSpace](https://devspace.sh/cli/docs/introduction) as Inner loop framework. DevSpace runs as a single binary CLI tool directly on your computer and ideally, you use it straight from the terminal within your IDE. DevSpace does not require a server-side component as it communicates directly to your Kubernetes cluster using your kube-context, just like kubectl.
DevSpace allows you to store all your workflows in one declarative config file: [devspace.yaml](./devspace.yaml). This repository has devspace.yaml for Azure vote App that includes both font-end and back-end.
### Inner-Loop Flow
1. Rename `.env.template` to `.env` and run `source .env` for setting config values.
1. Run `devspace use context` and select kubernetes cluster followed by `devspace use namespace <namespace_name>`
1. Post making changes to application code run `devspace dev` to instantly run Azure front-end container along with its dependencies in target cluster.
Running `devspace dev` will also implicitly generate manifest required to run 'Azure Vote App'. To explicitly generate manifest Run `devspace run gen-manifest`
1. Post running `devspace dev`, you can access Azure front-end through the port forwarding configuration specified in devspace.yaml e.g `http://localhost:8085/`
1. Running `devspace dev` also syncs app files into containers and you can continue making changes to app code without rebuilding image.
1. After the changes are finalized and tested push a new image to Azure Container registry by running `devspace build`
1. Run `devspace deploy` to build container image and deploy application to target cluster.
1. Run `devspace purge` to purge deployed application in target cluster.

70
devspace.yaml Normal file
Просмотреть файл

@ -0,0 +1,70 @@
version: v1beta10
# `vars` specifies variables which may be used as in devspace.yaml
vars:
- name: REGISTRY_PASSWORD
password: true
pullSecrets:
- registry: ${REGISTRY_NAME}.azurecr.io
username: ${REGISTRY_USERNAME}
password: ${REGISTRY_PASSWORD}
# `images` specifies all images that may need to be built for this project
images:
frontend: # This image is called `frontend` and this name `frontend` is referenced multiple times in the config below
image: ${REGISTRY_NAME}.azurecr.io/azvote/azure-vote-front
tags:
- v2
dockerfile: ./azure-vote/src/azure-vote-front/Dockerfile
context: ./azure-vote/src/azure-vote-front/
build:
disabled: true
backend: # This image is called `backend` and this name `backend` is referenced multiple times in the config below
image: ${REGISTRY_NAME}.azurecr.io/azvote/azure-vote-back
tags:
- 6.0.8
dockerfile: ./azure-vote/src/azure-vote-back/Dockerfile
context: ./azure-vote/src/azure-vote-back/
build:
disabled: true
# `deployments` tells DevSpace how to deploy this project
deployments:
- name: azure-vote-front
# This deployment uses `kubectl` but you can also define `helm` deployments
kubectl:
kustomize: true
manifests:
- ./azure-vote/manifests/azure-vote/kustomize/base
# `dev` only applies when you run `devspace dev`
dev:
#`dev.sync` configures a file sync between our Pods in k8s and your local project files
sync:
- imageName: frontend # Select the Pod that runs our `frontend` image
localSubPath: ./azure-vote/src/azure-vote-front/
containerPath: /app
ports:
- imageName: frontend
forward:
- port: 8085
remotePort: 80
open:
- url: http://localhost:8085/
# Run `devspace run gen-manifest` to generate manifest for azure-vote-front and azure-vote-back. Generated manifest will be ignored by git.
commands:
- name: gen-manifest
command: "./utils/generate-manifests-dev.sh ./azure-vote/manifests"
hooks:
- command: "./utils/generate-manifests-dev.sh ./azure-vote/manifests"
when:
before:
deployments: all

Просмотреть файл

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Generates K8s manifests from Helm + Kustomize templates
# Uses env variables to substitute values
# Requires to be installed:
# - helm
# - kubectl
# - envsubst (https://command-not-found.com/envsubst)
#
# Usage:
# generate-manifests.sh FOLDER_WITH_MANIFESTS GENERATED_MANIFESTS_FOLDER
# e.g.:
# generate-manifests-dev.sh cloud-native-ops/azure-vote/manifests
# Substitute env variables in all yaml files in the manifest folder
for file in `find $1 -name '*.yaml'`; do envsubst <"$file" > "$file"1 && mv "$file"1 "$file"; done
# Generate manifests
for app in `find $1 -maxdepth 1 -mindepth 1 -type d `; do \
helm template "$app"/helm > "$app"/kustomize/base/manifests.yaml
done
pwd