feat(deploy): test deployment to kubernetes azure #20
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: Python Continuous Integration | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
#env: | |
# PYTHON_VERSION: 3.11 | |
# NODE_VERSION: 18 | |
permissions: | |
id-token: write | |
contents: write | |
packages: write | |
jobs: | |
tags: | |
runs-on: ubuntu-latest | |
outputs: | |
new_version: ${{ steps.tag.outputs.new_version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Bump version and push tag | |
id: tag_version | |
if: github.ref == 'refs/heads/main' | |
uses: mathieudutour/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Add tag to output step for main branch | |
id: tag | |
run: | | |
if [ '${{ github.ref }}' = 'refs/heads/main' ]; then | |
echo "new_version=${{ steps.tag_version.outputs.new_version }}" >> $GITHUB_OUTPUT | |
else | |
echo "new_version=pr-${{ github.event.number }}-${{ github.run_number }}" >> $GITHUB_OUTPUT | |
fi | |
build_docker_api: | |
needs: [tags] | |
uses: ./.github/workflows/docker.yml | |
with: | |
image_name: "transcriptor-api" | |
image_version: ${{ needs.tags.outputs.new_version }} | |
image_build_args: "" | |
image_context: ./production/api | |
image_file: "./production/api/Dockerfile" | |
docker_registry: "ghcr.io" | |
docker_repository: "guillaume-chervet" | |
secrets: | |
DOCKER_USERNAME: ${{ github.actor }} | |
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | |
build_docker_webapp: | |
needs: [tags] | |
uses: ./.github/workflows/docker.yml | |
with: | |
image_name: "transcriptor-webapp" | |
image_version: ${{ needs.tags.outputs.new_version }} | |
image_build_args: "" | |
image_context: ./production/webapp | |
image_file: "./production/webapp/Dockerfile" | |
docker_registry: "ghcr.io" | |
docker_repository: "guillaume-chervet" | |
secrets: | |
DOCKER_USERNAME: ${{ github.actor }} | |
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [tags, build_docker_api, build_docker_webapp] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Azure Login | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_wrapper: false | |
- name: Terraform Init | |
working-directory: deploy/terraform | |
env: | |
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
run: terraform init | |
- name: Import Resource Group if Exists | |
working-directory: deploy/terraform | |
run: | | |
terraform state list | grep "azurerm_resource_group.aks_rg" || terraform import azurerm_resource_group.aks_rg /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/aks-resource-group | |
- name: Terraform Apply | |
env: | |
TF_VAR_subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
run: terraform apply -auto-approve | |
working-directory: deploy/terraform | |
- name: Setup kubectl | |
env: | |
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
run: | | |
az aks get-credentials --resource-group "aks-resource-group" --name "aks-cluster" | |
- name: Apply Kubernetes Deployment | |
working-directory: deploy/kubernetes | |
run: | | |
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash | |
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx | |
helm repo update | |
helm install ingress-nginx ingress-nginx/ingress-nginx | |
sed -i 's/:latest/:${{ needs.tags.outputs.new_version }}/g' api-deployment.yaml | |
sed -i 's/:latest/:${{ needs.tags.outputs.new_version }}/g' webapp-deployment.yaml | |
kubectl apply -f webapp-deployment.yaml | |
kubectl apply -f webapp-service.yaml | |
kubectl apply -f api-deployment.yaml | |
kubectl apply -f api-service.yaml |