diff --git a/.github/workflows/build-production.yml b/.github/workflows/build-production.yml new file mode 100644 index 00000000..9da7548c --- /dev/null +++ b/.github/workflows/build-production.yml @@ -0,0 +1,80 @@ +name: Build and push the tagged build to production + +on: + push: + tags: + - 'v*' + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build_push_image: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Docker Setup Buildx + # You may pin to the exact commit or the version. + # uses: docker/setup-buildx-action@0d135e0c2fc0dba0729c1a47ecfcf5a3c7f8579e + uses: docker/setup-buildx-action@v1.3.0 + # Runs a single command using the runners shell + - name: Docker Login + # You may pin to the exact commit or the version. + # uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + uses: docker/login-action@v1.9.0 + with: + registry: ${{ secrets.ACR_NAME }} + username: ${{ secrets.ACR_LOGIN }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Create Tag + id: gen_tags + run: | + echo '::set-output name=tags::'"${GITHUB_REF/refs\/tags\//}" + - name: Build and push Docker images + # You may pin to the exact commit or the version. + # uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + uses: docker/build-push-action@v2.5.0 + with: + context: . + tags: ${{ secrets.ACR_NAME }}/contoso-website:${{ steps.gen_tags.outputs.tags }} + push: true + + deploy: + runs-on: ubuntu-latest + needs: build_push_image + steps: + - uses: actions/checkout@v2.3.4 + + - name: Install Helm + uses: Azure/setup-helm@v1 + with: + version: v3.3.1 + + - name: Azure Kubernetes set context + uses: Azure/aks-set-context@v1.1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + resource-group: mslearn-gh-pipelines-22922 + cluster-name: contoso-video + + # ... File omitted + - name: Run Helm Deploy + run: | + helm upgrade \ + --install \ + --create-namespace \ + --atomic \ + --wait \ + --namespace production \ + contoso-website \ + ./kubernetes/contoso-website \ + --set image.repository=${{ secrets.ACR_NAME }} \ + --set dns.name=${{ secrets.DNS_NAME }} \ + --set image.tag=${GITHUB_REF##*/} + + diff --git a/.github/workflows/build-staging.yml b/.github/workflows/build-staging.yml new file mode 100644 index 00000000..ee15bd89 --- /dev/null +++ b/.github/workflows/build-staging.yml @@ -0,0 +1,63 @@ +name: Build and push the latest build to staging + +on: + push: + branches: [ main ] + +jobs: + build_push_image: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Buildx + uses: docker/setup-buildx-action@v1 + + - name: Docker Login + uses: docker/login-action@v1.9.0 + with: + registry: ${{ secrets.ACR_NAME }} + username: ${{ secrets.ACR_LOGIN }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Build and push staging images + uses: docker/build-push-action@v2.4.0 + with: + context: . + tags: ${{ secrets.ACR_NAME }}/contoso-website:latest + push: true + + deploy: + runs-on: ubuntu-latest + needs: build_push_image + steps: + - uses: actions/checkout@v2.3.4 + + - name: Install Helm + uses: Azure/setup-helm@v1 + with: + version: v3.3.1 + + - name: Azure Kubernetes set context + uses: Azure/aks-set-context@v1.1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + resource-group: mslearn-gh-pipelines-22922 + cluster-name: contoso-video + + # ... File omitted + - name: Run Helm Deploy + run: | + helm upgrade \ + --install \ + --create-namespace \ + --atomic \ + --wait \ + --namespace staging \ + contoso-website \ + ./kubernetes/contoso-website \ + --set image.repository=${{ secrets.ACR_NAME }} \ + --set dns.name=${{ secrets.DNS_NAME }} + + diff --git a/kubernetes/contoso-website/.helmignore b/kubernetes/contoso-website/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/kubernetes/contoso-website/.helmignore @@ -0,0 +1,23 @@ +# 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 +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/kubernetes/contoso-website/Chart.yaml b/kubernetes/contoso-website/Chart.yaml new file mode 100644 index 00000000..29dcab4c --- /dev/null +++ b/kubernetes/contoso-website/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v2 +name: contoso-website +description: Chart for the Contoso company website +version: 0.1.0 \ No newline at end of file diff --git a/kubernetes/deployment.yaml b/kubernetes/contoso-website/templates/deployment.yaml similarity index 74% rename from kubernetes/deployment.yaml rename to kubernetes/contoso-website/templates/deployment.yaml index 88ad20db..97f336de 100644 --- a/kubernetes/deployment.yaml +++ b/kubernetes/contoso-website/templates/deployment.yaml @@ -2,6 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: contoso-website + namespace: {{ default "staging" .Release.Namespace }} spec: selector: matchLabels: @@ -12,7 +13,7 @@ spec: app: contoso-website spec: containers: - - image: !IMAGE! + - image: {{ .Values.image.registry }}/{{ .Values.image.name }}:{{ default "latest" .Values.image.tag }} name: contoso-website resources: requests: diff --git a/kubernetes/ingress.yaml b/kubernetes/contoso-website/templates/ingress.yaml similarity index 68% rename from kubernetes/ingress.yaml rename to kubernetes/contoso-website/templates/ingress.yaml index 777d3756..faa3b5b7 100644 --- a/kubernetes/ingress.yaml +++ b/kubernetes/contoso-website/templates/ingress.yaml @@ -2,11 +2,12 @@ apiVersion: extensions/v1beta1 kind: Ingress metadata: name: contoso-website + namespace: {{ default "staging" .Release.Namespace }} annotations: kubernetes.io/ingress.class: addon-http-application-routing spec: rules: - - host: contoso.!DNS! + - host: contoso-{{ default "staging" .Release.Namespace }}.{{ .Values.dns.name }} http: paths: - backend: diff --git a/kubernetes/service.yaml b/kubernetes/contoso-website/templates/service.yaml similarity index 78% rename from kubernetes/service.yaml rename to kubernetes/contoso-website/templates/service.yaml index a0d46d66..23430fac 100644 --- a/kubernetes/service.yaml +++ b/kubernetes/contoso-website/templates/service.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: Service metadata: name: contoso-website + namespace: {{ default "staging" .Release.Namespace }} spec: ports: - port: 80 diff --git a/kubernetes/contoso-website/values.yaml b/kubernetes/contoso-website/values.yaml new file mode 100644 index 00000000..245350f9 --- /dev/null +++ b/kubernetes/contoso-website/values.yaml @@ -0,0 +1,7 @@ +image: + registry: contosocontainerregistry32723.azurecr.io + name: contoso-website + tag: latest + +dns: + name: ebcabb15a8b447c2b70f.eastus.aksapp.io \ No newline at end of file diff --git a/test b/test new file mode 100644 index 00000000..ff57e617 --- /dev/null +++ b/test @@ -0,0 +1 @@ +testr diff --git a/test file b/test file new file mode 100644 index 00000000..9daeafb9 --- /dev/null +++ b/test file @@ -0,0 +1 @@ +test