diff --git a/.github/workflows/k8s-deploy.yml b/.github/workflows/k8s-deploy.yml new file mode 100644 index 0000000..6cd2fbc --- /dev/null +++ b/.github/workflows/k8s-deploy.yml @@ -0,0 +1,89 @@ +name: k8s-deploy + +on: + push: + branches: + - master + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + production-deploy: + runs-on: ubuntu-latest + + steps: + - name: Check out latest commit + uses: actions/checkout@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: osuAkatsuki/avatars-service + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: | + ${{ secrets.DOCKERHUB_USERNAME }}/avatars-service:latest + ${{ secrets.DOCKERHUB_USERNAME }}/avatars-service:${{ github.sha }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Get kubeconfig from github secrets + run: | + mkdir -p $HOME/.kube + echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config + sudo chown $(id -u):$(id -g) $HOME/.kube/config + chmod 600 $HOME/.kube/config + + - name: Install helm + uses: azure/setup-helm@v3 + with: + version: "latest" + token: ${{ secrets.GITHUB_TOKEN }} + id: install + + - name: Install helm-diff + run: helm plugin install https://github.com/databus23/helm-diff + + - name: Checkout common-helm-charts repo + uses: actions/checkout@v3 + with: + repository: osuAkatsuki/common-helm-charts + token: ${{ secrets.COMMON_HELM_CHARTS_PAT }} + path: common-helm-charts + + - name: Clear pending deployments + run: | + kubectl delete secret -l 'status in (pending-install, pending-upgrade, pending-rollback),name=avatars-service-production' + + - name: Show manifest diff since previous release + run: | + helm diff upgrade \ + --allow-unreleased \ + --color=true \ + --values chart/values.yaml \ + avatars-service-production \ + common-helm-charts/microservice-base/ + + - name: Deploy service to production cluster + run: | + helm upgrade \ + --install \ + --atomic \ + --wait --timeout 10m \ + --cleanup-on-fail \ + --values chart/values.yaml \ + avatars-service-production \ + common-helm-charts/microservice-base/ diff --git a/main.py b/main.py old mode 100644 new mode 100755