Skip to content

Commit

Permalink
workflow: deploy release to aks
Browse files Browse the repository at this point in the history
deploy to AKS when a release is published
  • Loading branch information
yifan authored Dec 6, 2022
1 parent fb0f487 commit 3ee9d49
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 3 deletions.
114 changes: 114 additions & 0 deletions .github/workflows/azure-kubernetes-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# This workflow will build and push an application to a Azure Kubernetes Service (AKS) cluster when you push your code
#
# This workflow assumes you have already created the target AKS cluster and have created an Azure Container Registry (ACR)
# The ACR should be attached to the AKS cluster
# For instructions see:
# - https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough-portal
# - https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal
# - https://learn.microsoft.com/en-us/azure/aks/cluster-container-registry-integration?tabs=azure-cli#configure-acr-integration-for-existing-aks-clusters
# - https://github.com/Azure/aks-create-action
#
# To configure this workflow:
#
# 1. Set the following secrets in your repository (instructions for getting these can be found at https://docs.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-cli%2Clinux):
# - AZURE_CLIENT_ID
# - AZURE_TENANT_ID
# - AZURE_SUBSCRIPTION_ID
#
# 2. Set the following environment variables (or replace the values below):
# - AZURE_CONTAINER_REGISTRY (name of your container registry / ACR)
# - RESOURCE_GROUP (where your cluster is deployed)
# - CLUSTER_NAME (name of your AKS cluster)
# - CONTAINER_NAME (name of the container image you would like to push up to your ACR)
# - IMAGE_PULL_SECRET_NAME (name of the ImagePullSecret that will be created to pull your ACR image)
# - DEPLOYMENT_MANIFEST_PATH (path to the manifest yaml for your deployment)
#
# For more information on GitHub Actions for Azure, refer to https://github.com/Azure/Actions
# For more samples to get started with GitHub Action workflows to deploy to Azure, refer to https://github.com/Azure/actions-workflow-samples
# For more options with the actions used below please refer to https://github.com/Azure/login

name: Build and deploy an app to AKS

on:
release:
types: [published]
workflow_dispatch:

env:
AZURE_CONTAINER_REGISTRY: "meganews"
CONTAINER_NAME: "apihub"
RESOURCE_GROUP: "meganews"
CLUSTER_NAME: "apihub"
NAMESPACE: "apihub"
DEPLOYMENT_MANIFEST_PATH: |
manifests/apihub-server.yaml
manifests/apihub-result.yaml
jobs:
buildImage:
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
id-token: write
steps:
# Checks out the repository this file is in
- uses: actions/checkout@v3

# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

# # Connect to Azure Container registry (ACR)
# - uses: azure/docker-login@v1
# with:
# login-server: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io
# username: ${{ secrets.REGISTRY_USERNAME }}
# password: ${{ secrets.REGISTRY_PASSWORD }}

# Builds and pushes an image up to your Azure Container Registry
- name: Build and push image to ACR
run: |
az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.ref_name }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
deploy:
runs-on: ubuntu-latest
environment: production
permissions:
actions: read
contents: read
id-token: write
needs: [buildImage]
steps:
# Checks out the repository this file is in
- uses: actions/checkout@v3

# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

# Retrieves your Azure Kubernetes Service cluster's kubeconfig file
- name: Get K8s context
uses: azure/aks-set-context@v3
with:
resource-group: ${{ env.RESOURCE_GROUP }}
cluster-name: ${{ env.CLUSTER_NAME }}

# Deploys application based on given manifest file
- name: Deploys application
uses: Azure/k8s-deploy@v4
with:
action: deploy
manifests: ${{ env.DEPLOYMENT_MANIFEST_PATH }}
images: |
${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.ref_name }}
namespace: ${{ env.NAMESPACE }}

6 changes: 3 additions & 3 deletions .github/workflows/pytest-redis-postgres-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: poetry pytest workflow
on: push
on: [pull_request]

jobs:
# Label of the container job
Expand Down Expand Up @@ -44,10 +44,10 @@ jobs:
steps:
# Downloads a copy of the code in your repository before running CI tests
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ env
dist
**.apihub
**/.DS_Store
.secrets
48 changes: 48 additions & 0 deletions manifests/apihub-result.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: apihub-result
name: apihub-result
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: apihub-result
template:
metadata:
labels:
app: apihub-result
spec:
containers:
- command:
- poetry
- run
- apihub_result
envFrom:
- configMapRef:
name: pipeline-config
- configMapRef:
name: result-config
image: meganews.azurecr.io/apihub:v0.1.2a6
imagePullPolicy: IfNotPresent
name: result
ports:
- containerPort: 8000
name: http-metrics
protocol: TCP
resources:
limits:
memory: 1Gi
requests:
cpu: 100m
memory: 256Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
65 changes: 65 additions & 0 deletions manifests/apihub-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: apihub-server
name: apihub-server
namespace: apihub
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: apihub-server
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: apihub-server
spec:
containers:
- command:
- poetry
- run
- apihub_server
envFrom:
- configMapRef:
name: pipeline-config
- configMapRef:
name: server-config
image: meganews.azurecr.io/apihub:v0.0.0a0
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: 5000
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 30
name: server
ports:
- containerPort: 5000
name: http-metrics
protocol: TCP
resources:
limits:
memory: 1Gi
requests:
cpu: 100m
memory: 256Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30

0 comments on commit 3ee9d49

Please sign in to comment.