backend - towards a better gitops deploy strategy #70
@@ -3,6 +3,9 @@ on:
 | 
				
			|||||||
    tags:
 | 
					    tags:
 | 
				
			||||||
      - v*
 | 
					      - v*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					permissions:
 | 
				
			||||||
 | 
					  pull-requests: write
 | 
				
			||||||
 | 
					
 | 
				
			||||||
name: Build and deploy the backend to production
 | 
					name: Build and deploy the backend to production
 | 
				
			||||||
 | 
					
 | 
				
			||||||
jobs:
 | 
					jobs:
 | 
				
			||||||
@@ -10,15 +13,7 @@ jobs:
 | 
				
			|||||||
    name: Build and push image
 | 
					    name: Build and push image
 | 
				
			||||||
    uses: ./.gitea/workflows/workflow_build-image.yaml
 | 
					    uses: ./.gitea/workflows/workflow_build-image.yaml
 | 
				
			||||||
    with:
 | 
					    with:
 | 
				
			||||||
      tag: stable
 | 
					      # sets the tag to the git tag that triggered the workflow - the deployment (configured in a separate repository) will use this tag and be deployed to production by argocd
 | 
				
			||||||
 | 
					      tag: ${{ github.ref_name }}
 | 
				
			||||||
    secrets:
 | 
					    secrets:
 | 
				
			||||||
      PACKAGE_REGISTRY_ACCESS: ${{ secrets.PACKAGE_REGISTRY_ACCESS }}
 | 
					      PACKAGE_REGISTRY_ACCESS: ${{ secrets.PACKAGE_REGISTRY_ACCESS }}
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  deploy-prod:
 | 
					 | 
				
			||||||
    name: Deploy to production
 | 
					 | 
				
			||||||
    uses: ./.gitea/workflows/workflow_deploy-container.yaml
 | 
					 | 
				
			||||||
    with:
 | 
					 | 
				
			||||||
      overlay: prod
 | 
					 | 
				
			||||||
    secrets:
 | 
					 | 
				
			||||||
      KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
 | 
					 | 
				
			||||||
    needs: build-and-push
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,15 +12,32 @@ jobs:
 | 
				
			|||||||
    name: Build and push image
 | 
					    name: Build and push image
 | 
				
			||||||
    uses: ./.gitea/workflows/workflow_build-image.yaml
 | 
					    uses: ./.gitea/workflows/workflow_build-image.yaml
 | 
				
			||||||
    with:
 | 
					    with:
 | 
				
			||||||
      tag: unstable
 | 
					      # sets a unique tag for each commit in the PR - this gets deployed to a separate application instance using argocd
 | 
				
			||||||
 | 
					      tag: sha${{ github.sha }}
 | 
				
			||||||
    secrets:
 | 
					    secrets:
 | 
				
			||||||
      PACKAGE_REGISTRY_ACCESS: ${{ secrets.PACKAGE_REGISTRY_ACCESS }}
 | 
					      PACKAGE_REGISTRY_ACCESS: ${{ secrets.PACKAGE_REGISTRY_ACCESS }}
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  deploy-prod:
 | 
					  notify:
 | 
				
			||||||
    name: Deploy to staging
 | 
					    runs-on: ubuntu-latest
 | 
				
			||||||
    uses: ./.gitea/workflows/workflow_deploy-container.yaml
 | 
					    name: Add a comment to the PR to notify about the deployment
 | 
				
			||||||
    with:
 | 
					    steps:
 | 
				
			||||||
      overlay: stg
 | 
					      - name: Download gitea client
 | 
				
			||||||
    secrets:
 | 
					        run: |
 | 
				
			||||||
      KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
 | 
					          curl -sSL -o tea https://dl.gitea.com/tea/0.11.0/tea-0.11.0-linux-amd64
 | 
				
			||||||
    needs: build-and-push
 | 
					          chmod +x tea
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: Login
 | 
				
			||||||
 | 
					        run: |
 | 
				
			||||||
 | 
					          ./tea login add --url git.kluster.moll.re --name bot --token ${{ secrets.GITEA_TOKEN }}
 | 
				
			||||||
 | 
					          ./tea login default
 | 
				
			||||||
 | 
					      - name: Post comment
 | 
				
			||||||
 | 
					        run: |
 | 
				
			||||||
 | 
					          ./tea comment --repo anydev/anyway --login bot ${{ github.event.number }} """
 | 
				
			||||||
 | 
					          The backend has been deployed to staging with url https://pr-${{ github.event.number }}.anyway-stg.anydev.info. Check the deployment status in ArgoCD:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          [](https://argocd.kluster.moll.re/applications/anydev-anyway-backend-stg-pr-${{ github.event.number }})
 | 
				
			||||||
 | 
					          """
 | 
				
			||||||
 | 
					        env:
 | 
				
			||||||
 | 
					          GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
 | 
				
			||||||
 | 
					          GITEA_BASE_URL: ${{ secrets.GITEA_BASE_URL }}
 | 
				
			||||||
 | 
					          GITEA_REPO: ${{ secrets.GITEA_REPO }}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,35 +0,0 @@
 | 
				
			|||||||
on:
 | 
					 | 
				
			||||||
  workflow_call:
 | 
					 | 
				
			||||||
    inputs:
 | 
					 | 
				
			||||||
      overlay:
 | 
					 | 
				
			||||||
        required: true
 | 
					 | 
				
			||||||
        type: string
 | 
					 | 
				
			||||||
    secrets:
 | 
					 | 
				
			||||||
      KUBE_CONFIG:
 | 
					 | 
				
			||||||
        required: true
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
name: Deploy the newly built container
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
jobs:
 | 
					 | 
				
			||||||
  deploy:
 | 
					 | 
				
			||||||
    name: Deploy
 | 
					 | 
				
			||||||
    runs-on: ubuntu-latest
 | 
					 | 
				
			||||||
    steps:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    - uses: https://gitea.com/actions/checkout@v4
 | 
					 | 
				
			||||||
      with:
 | 
					 | 
				
			||||||
        submodules: true
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    - name: setup kubectl
 | 
					 | 
				
			||||||
      uses: https://github.com/azure/setup-kubectl@v4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    - name: Set kubeconfig
 | 
					 | 
				
			||||||
      run: |
 | 
					 | 
				
			||||||
        echo "${{ secrets.KUBE_CONFIG }}" > kubeconfig
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    - name: Deploy to k8s
 | 
					 | 
				
			||||||
      run: |
 | 
					 | 
				
			||||||
        kubectl apply -k backend/deployment/overlays/${{ inputs.overlay }} --kubeconfig=kubeconfig
 | 
					 | 
				
			||||||
        kubectl -n anyway-backend rollout restart deployment/anyway-backend-${{ inputs.overlay }} --kubeconfig=kubeconfig
 | 
					 | 
				
			||||||
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1 +1,2 @@
 | 
				
			|||||||
cache/
 | 
					cache/
 | 
				
			||||||
 | 
					.direnv/
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							@@ -1,3 +0,0 @@
 | 
				
			|||||||
[submodule "backend/deployment"]
 | 
					 | 
				
			||||||
	path = backend/deployment
 | 
					 | 
				
			||||||
	url = https://git.kluster.moll.re/anydev/anyway-backend-deployment
 | 
					 | 
				
			||||||
							
								
								
									
										8
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
								
							@@ -9,9 +9,7 @@
 | 
				
			|||||||
            "name": "Backend - debug",
 | 
					            "name": "Backend - debug",
 | 
				
			||||||
            "type": "debugpy",
 | 
					            "type": "debugpy",
 | 
				
			||||||
            "request": "launch",
 | 
					            "request": "launch",
 | 
				
			||||||
            "env": {
 | 
					            "envFile": "${workspaceFolder}/backend/debug.env",
 | 
				
			||||||
                "DEBUG": "true"
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            "jinja": true,
 | 
					            "jinja": true,
 | 
				
			||||||
            "cwd": "${workspaceFolder}/backend",
 | 
					            "cwd": "${workspaceFolder}/backend",
 | 
				
			||||||
            "module": "fastapi",
 | 
					            "module": "fastapi",
 | 
				
			||||||
@@ -25,9 +23,7 @@
 | 
				
			|||||||
            "type": "debugpy",
 | 
					            "type": "debugpy",
 | 
				
			||||||
            "request": "launch",
 | 
					            "request": "launch",
 | 
				
			||||||
            "program": "src/tester.py",
 | 
					            "program": "src/tester.py",
 | 
				
			||||||
            "env": {
 | 
					            "envFile": "${workspaceFolder}/backend/debug.env",
 | 
				
			||||||
                "DEBUG": "true"
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            "cwd": "${workspaceFolder}/backend"
 | 
					            "cwd": "${workspaceFolder}/backend"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        // frontend - flutter app
 | 
					        // frontend - flutter app
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "nixEnvSelector.nixFile": "${workspaceFolder}/default.nix"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										5
									
								
								backend/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								backend/.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,3 +1,6 @@
 | 
				
			|||||||
 | 
					# all .env files
 | 
				
			||||||
 | 
					*.env
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# osm-cache
 | 
					# osm-cache
 | 
				
			||||||
cache_XML/
 | 
					cache_XML/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -165,4 +168,4 @@ cython_debug/
 | 
				
			|||||||
#  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
 | 
					#  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
 | 
				
			||||||
#  and can be added to the global gitignore or merged into this file.  For a more nuclear
 | 
					#  and can be added to the global gitignore or merged into this file.  For a more nuclear
 | 
				
			||||||
#  option (not recommended) you can uncomment the following to ignore the entire idea folder.
 | 
					#  option (not recommended) you can uncomment the following to ignore the entire idea folder.
 | 
				
			||||||
#.idea/
 | 
					#.idea/
 | 
				
			||||||
 
 | 
				
			|||||||
 Submodule backend/deployment deleted from 904f16bfc0
									
								
							
							
								
								
									
										17
									
								
								default.nix
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								default.nix
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					{ pkgs ? import <nixpkgs> { config.android_sdk.accept_license = true; config.allowUnfree = true; } }:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pkgs.mkShell {
 | 
				
			||||||
 | 
					    buildInputs = [
 | 
				
			||||||
 | 
					        pkgs.flutter
 | 
				
			||||||
 | 
					        #pkgs.android-tools  # for adb
 | 
				
			||||||
 | 
					        #pkgs.openjdk        # required for Android builds
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Set up Android SDK paths if needed
 | 
				
			||||||
 | 
					    shellHook = ''
 | 
				
			||||||
 | 
					        export ANDROID_SDK_ROOT=${pkgs.androidsdk}/libexec/android-sdk
 | 
				
			||||||
 | 
					        export PATH=$PATH:${pkgs.androidsdk}/libexec/android-sdk/platform-tools
 | 
				
			||||||
 | 
					        echo "Flutter dev environment ready. 'adb' and 'flutter' are available."
 | 
				
			||||||
 | 
					    '';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Reference in New Issue
	
	Block a user