Add Opentelemetry #6
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 CI/CD Pipeline with k8s | |
on: | |
push: | |
branches: | |
- '*' | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
KUBE_CONFIG : ${{ secrets.KUBE_CONFIG }} | |
env_name: ${{startsWith(github.ref, 'refs/heads/release-') && 'prod' || 'dev'}} | |
api_host : ${{startsWith(github.ref, 'refs/heads/release-') && 'provisioner.zerofiltre.tech' || 'provisioner-dev.zerofiltre.tech'}} | |
DOCKER_TAG_SUFFIX: ${{startsWith(github.ref, 'refs/heads/release-') && 'stable' || 'unstable'}} | |
replicas : ${{startsWith(github.ref, 'refs/heads/release-') && 1 || 1 }} | |
requests_cpu : ${{startsWith(github.ref, 'refs/heads/release-') && 0.1 || 0.1 }} | |
requests_memory : ${{startsWith(github.ref, 'refs/heads/release-') && '0.5Gi' || '0.5Gi' }} | |
limits_cpu : ${{startsWith(github.ref, 'refs/heads/release-') && 0.5 || 0.5 }} | |
limits_memory : ${{startsWith(github.ref, 'refs/heads/release-') && '1.5Gi' || '1Gi' }} | |
domain_name : ${{startsWith(github.ref, 'refs/heads/release-') && 'provisioner.zerofiltre.tech' || 'provisioner-dev.zerofiltre.tech'}} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Docker Login | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Docker Login | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
push: true | |
tags: imzerofiltre/zerofiltretech-provisioner:${{ github.run_number }}_${{ env.DOCKER_TAG_SUFFIX }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
build-args: PROFILE=${{ env.env_name }} | |
- name: Set up kubectl | |
uses: tale/kubectl-action@v1 | |
with: | |
base64-kube-config: ${{ secrets.KUBE_CONFIG }} | |
- name: Set up k8s manifest | |
run: | | |
envsubst < microservice.yaml > k8s.yml | |
cat k8s.yml | |
- name: Deploy to k8s | |
run: | | |
kubectl apply -f k8s.yml | |
kubectl set image deployment/zerofiltretech-provisioner-${{ env.env_name }} zerofiltretech-provisioner-${{ env.env_name }}=imzerofiltre/zerofiltretech-provisioner:${{ github.run_number }}_${{ env.DOCKER_TAG_SUFFIX }} -n zerofiltretech-${{ env.env_name }} | |
kubectl annotate deployment zerofiltretech-provisioner-${{ env.env_name }} kubernetes.io/change-cause="version change to: ${{ github.run_number }}_${{ env.DOCKER_TAG_SUFFIX }} " -n zerofiltretech-${{ env.env_name }} --overwrite=true | |
if ! kubectl rollout status -w deployment/zerofiltretech-provisioner-${{ env.env_name }} -n zerofiltretech-${{ env.env_name }}; then | |
kubectl rollout undo deployment.v1.apps/zerofiltretech-provisioner-${{ env.env_name }} -n zerofiltretech-${{ env.env_name }} | |
kubectl rollout status deployment/zerofiltretech-provisioner-${{ env.env_name }} -n zerofiltretech-${{ env.env_name }} | |
exit 1 | |
fi | |
- name: Get commit author email | |
if: ${{ failure() }} | |
run: | | |
COMMIT_AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae') | |
echo "COMMIT_AUTHOR_EMAIL=$COMMIT_AUTHOR_EMAIL" >> $GITHUB_ENV | |
- name: Send email on failure | |
uses: dawidd6/[email protected] | |
with: | |
server_address: smtp.gmail.com | |
server_port: 587 | |
username: ${{ secrets.EMAIL_USERNAME }} | |
password: ${{ secrets.EMAIL_PASSWORD }} | |
subject: "Workflow failed on ${{ github.repository }}/${{ github.head_ref }} (commit ${{ github.sha }})" | |
body: | | |
Workflow failed on ${{ github.repository }}/${{ github.head_ref }} (commit ${{ github.sha }}). \nSee the workflow run log for more details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
from: "GitHub Actions <${{ vars.EMAIL_FROM }}>" | |
to: ${{ env.COMMIT_AUTHOR_EMAIL }} | |
if: ${{ failure() }} | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |