diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..1432919 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,47 @@ +name: CI +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + + - uses: Azure/docker-login@v1 + with: + login-server: SHRegistry.azurecr.io + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - run: | + docker build . -t SHRegistry.azurecr.io/k8sdemo:${{ github.sha }} + docker push SHRegistry.azurecr.io/k8sdemo:${{ github.sha }} + + - name: Set Context for Azure Kubernetes Cluster using azure/aks-set-context@v1 action + uses: azure/aks-set-context@v1 + with: + creds: '${{ secrets.AZURE_CREDENTIALS }}' + cluster-name: Actionsdemo-aks + resource-group: ActionsDemo + + - uses: Azure/k8s-create-secret@v1 + with: + container-registry-url: SHRegistry.azurecr.io + container-registry-username: ${{ secrets.REGISTRY_USERNAME }} + container-registry-password: ${{ secrets.REGISTRY_PASSWORD }} + secret-name: demo-k8s-secret + + - uses: azure/k8s-bake@v1 + with: + renderEngine: 'helm2' + helmChart: './charts/' + releaseName: aksappupdemo + id: bake + + - uses: Azure/k8s-deploy@v1 + with: + manifests: ${{ steps.bake.outputs.manifestsBundle }} + images: | + SHRegistry.azurecr.io/k8sdemo:${{ github.sha }} + imagepullsecrets: | + demo-k8s-secret \ No newline at end of file diff --git a/charts/.helmignore b/charts/.helmignore new file mode 100644 index 0000000..f0c1319 --- /dev/null +++ b/charts/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/charts/Chart.yaml b/charts/Chart.yaml new file mode 100644 index 0000000..d6b3594 --- /dev/null +++ b/charts/Chart.yaml @@ -0,0 +1,4 @@ +name: javascript +description: A Helm chart for Kubernetes +apiVersion: v1 +version: v0.1.0 diff --git a/charts/templates/NOTES.txt b/charts/templates/NOTES.txt new file mode 100644 index 0000000..da948fa --- /dev/null +++ b/charts/templates/NOTES.txt @@ -0,0 +1,15 @@ + +{{- if contains "NodePort" .Values.service.type }} + Get the application URL by running these commands: + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT/login +{{- else if contains "LoadBalancer" .Values.service.type }} + Get the application URL by running these commands: + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get svc -w {{ template "fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.externalPort }} +{{- else }} + http://{{ .Release.Name }}.{{ .Values.basedomain }} to access your application +{{- end }} diff --git a/charts/templates/_helpers.tpl b/charts/templates/_helpers.tpl new file mode 100644 index 0000000..f0d83d2 --- /dev/null +++ b/charts/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/charts/templates/deployment.yaml b/charts/templates/deployment.yaml new file mode 100644 index 0000000..72e393b --- /dev/null +++ b/charts/templates/deployment.yaml @@ -0,0 +1,23 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ template "fullname" . }} + labels: + aksup: {{ default "aks-up-app" }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + aksup: {{ default "aks-up-app" }} + app: {{ template "fullname" . }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.internalPort }} + resources: +{{ toYaml .Values.resources | indent 12 }} diff --git a/charts/templates/ingress.yaml b/charts/templates/ingress.yaml new file mode 100644 index 0000000..974e6f6 --- /dev/null +++ b/charts/templates/ingress.yaml @@ -0,0 +1,17 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "fullname" . }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + rules: + - host: {{ .Release.Name }}.{{ .Values.basedomain }} + http: + paths: + - path: / + backend: + serviceName: {{ template "fullname" . }} + servicePort: {{ .Values.service.externalPort }} +{{- end -}} diff --git a/charts/templates/service.yaml b/charts/templates/service.yaml new file mode 100644 index 0000000..d524c8b --- /dev/null +++ b/charts/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "fullname" . }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + app: {{ template "fullname" . }} diff --git a/charts/values.yaml b/charts/values.yaml new file mode 100644 index 0000000..0290db3 --- /dev/null +++ b/charts/values.yaml @@ -0,0 +1,24 @@ +# Default values for node. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +image: + repository: SHRegistry.azurecr.io/k8sdemo + tag: ${{ github.sha }} + pullPolicy: IfNotPresent +nameOverride: "javascript" +fullnameOverride: "javascript" +service: + name: javascript + type: LoadBalancer + externalPort: 8080 + internalPort: 8080 +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi +ingress: + enabled: false