diff --git a/.github/workflows/car-demo-azure.yml b/.github/workflows/car-demo-azure.yml new file mode 100644 index 00000000..c6a3091e --- /dev/null +++ b/.github/workflows/car-demo-azure.yml @@ -0,0 +1,40 @@ +name: car-demo-common-service + +on: + push: + branches: [ main ] +env: + AKS_CLUSTER: ntdemocluster + AKS_NAMESPACE: default + +jobs: + setup-build-publish-deploy: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up JDK 19 + uses: actions/setup-java@v3 + with: + java-version: '19' + distribution: 'temurin' + cache: maven + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + - name: Azure CLI script + uses: azure/CLI@v1 + with: + azcliversion: 2.30.0 + inlineScript: | + az account show + az storage -h + - name: Build, Publish, and Deploy + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + . az-svc-deployment.sh diff --git a/az-svc-deployment.sh b/az-svc-deployment.sh new file mode 100644 index 00000000..6fe25f06 --- /dev/null +++ b/az-svc-deployment.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +AKS_CLUSTER="ntdemocluster" +SERVICE_NAME="admin-service" +DEPLOYMENT_NAME="admin-service" +RESOURCE_GROUP_NAME="az-nashtech-resource-group" + +az aks install-cli +echo "---------build and deploy $SERVICE_NAME-----------" +cd "$SERVICE_NAME" || exit +mvn clean install +echo "---------packaging done, start docker build-----------" +docker build -f Dockerfile --tag gcr.io/"$SERVICE_NAME":"$GITHUB_SHA" . +echo "--------docker build done, docker push---------------" +docker push gcr.io/"$SERVICE_NAME":"$GITHUB_SHA" +echo "--------pushed docker image, deploy to aks cluster--------------------------" + +az aks get-credentials --resource-group "$RESOURCE_GROUP_NAME" --name "$AKS_CLUSTER" +# setup kustomize +curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64 +chmod u+x ./kustomize + +# set docker image for kustomize +./kustomize edit set image gcr.io/IMAGE:TAG=gcr.io/"$SERVICE_NAME":"$GITHUB_SHA" +# deploy through kubectl +./kustomize build . | kubectl apply -f - +kubectl rollout status deployment/"$DEPLOYMENT_NAME" +kubectl get services -o wide +echo "-------------$SERVICE_NAME deployed on $CLUSTER_NAME----------" +