Skip to content

Commit

Permalink
dockerize & deploy in ci as k8s cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Nov 5, 2023
1 parent b3ba750 commit a355fec
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/k8s-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: k8s-deploy

on:
push:
branches:
- main
- k8s-deploy

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/new-cron

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/new-cron:latest
${{ secrets.DOCKERHUB_USERNAME }}/new-cron:${{ 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
- name: Deploy cronjob to production cluster
run: |
kubectl apply -f k8s/cronjob.yaml
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.9

WORKDIR /srv/root

COPY . .

RUN pip install -r requirements.txt

CMD ["python", "main.py"]
17 changes: 17 additions & 0 deletions k8s/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: new-cron-production
spec:
schedule: "*/10 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: new-cron-production
image: osuAkatsuki/new-cron:latest
imagePullPolicy: IfNotPresent
command:
- python3 main.py
restartPolicy: OnFailure
4 changes: 0 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/usr/bin/env python3.9
import ddtrace
ddtrace.patch_all()
from ddtrace.profiling import Profiler
Profiler().start()
from typing import Any
from typing import cast

Expand Down

0 comments on commit a355fec

Please sign in to comment.