This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy soemi-weather microservices to AKS | |
on: | |
push: | |
branches: [ "main" ] | |
workflow_dispatch: | |
env: | |
AZURE_CONTAINER_REGISTRY: "" | |
CONTAINER_NAME: "" | |
RESOURCE_GROUP: "" | |
CLUSTER_NAME: "" | |
DEPLOYMENT_MANIFEST_PATH: "" | |
jobs: | |
build-images: | |
permissions: | |
contents: read | |
id-token: write | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Get Short Commit SHA | |
run: | | |
echo "COMMIT_SHA_SHORT=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV | |
- name: Build docker images | |
run: | | |
echo "Building images" | |
docker build -t z100/soemi-woeb:${{ env.COMMIT_SHA_SHORT }} ./soemi-woeb | |
docker build -t z100/soemi-woers:${{ env.COMMIT_SHA_SHORT }} ./soemi-woers | |
docker build -t z100/soemi-proexy:${{ env.COMMIT_SHA_SHORT }} ./soemi-proexy | |
- name: Push docker images | |
run: | | |
echo "Login to dockerhub" | |
docker login -u ${{ secrets.DOCKERHUB_U }} -p ${{ secrets.DOCKERHUB_T }} | |
echo "Pushing images" | |
docker push z100/soemi-woeb:${{ env.COMMIT_SHA_SHORT }} | |
docker push z100/soemi-woers:${{ env.COMMIT_SHA_SHORT }} | |
docker push z100/soemi-proexy:${{ env.COMMIT_SHA_SHORT }} | |
deploy-services: | |
permissions: | |
actions: read | |
contents: read | |
id-token: write | |
runs-on: ubuntu-latest | |
needs: [ build-images ] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Get Short Commit SHA | |
run: | | |
echo "COMMIT_SHA_SHORT=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV | |
- name: Populate deployment.yaml with vars | |
run: | | |
sed -i "s|\$IMAGE_TAG|${{ env.COMMIT_SHA_SHORT }}|g" ./soemi-woeb/k8s/deployment.yaml | |
sed -i "s|\$IMAGE_TAG|${{ env.COMMIT_SHA_SHORT }}|g" ./soemi-woers/k8s/deployment.yaml | |
sed -i "s|\$IMAGE_TAG|${{ env.COMMIT_SHA_SHORT }}|g" ./soemi-proexy/k8s/deployment.yaml | |
- name: Azure login | |
uses: azure/login@v1.4.6 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Setup kubectl | |
uses: azure/setup-kubectl@v2.0 | |
- name: Set AKS credentials | |
run: | | |
az aks get-credentials --resource-group ${{ secrets.RESOURCE_GROUP }} --name ${{ secrets.CLUSTER_NAME }} --overwrite-existing | |
- name: Set kubectl context | |
run: | | |
kubectl config use-context ${{ secrets.CLUSTER_NAME }} | |
- name: Deploy microservices to AKS | |
run: | | |
echo "Deploying services" | |
kubectl replace --force -f ./soemi-moen/k8s | |
kubectl replace --force -f ./soemi-proexy/k8s | |
kubectl replace --force -f ./soemi-woeb/k8s | |
kubectl replace --force -f ./soemi-woers/k8s |