Deploy Main to Kubernetes #46
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: Deploy Main to Kubernetes | |
on: | |
workflow_run: | |
workflows: | |
- Build and Push Docker Image | |
types: | |
- completed | |
workflow_dispatch: | |
jobs: | |
deploy-main: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Check if running in a pull request | |
if: ${{ github.event_name == 'pull_request' }} | |
run: echo "Running in a pull request, aborting workflow." && exit 0 | |
- name: Deploy to Kubernetes | |
run: | | |
mkdir -p k8s | |
cat <<EOF > k8s/deployment.yaml | |
apiVersion: v1 | |
kind: Namespace | |
metadata: | |
name: killedby-latest | |
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: killedby-latest | |
namespace: killedby-latest | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: killedby-latest | |
template: | |
metadata: | |
labels: | |
app: killedby-latest | |
spec: | |
containers: | |
- name: killedby-latest | |
image: bacherik/killedby:latest | |
imagePullPolicy: Always | |
env: | |
- name: GITHUB_USERNAME | |
value: "bacherik" | |
- name: GITHUB_REPOSITORY | |
value: "killedby.json" | |
- name: UPDATE_TOKEN | |
value: "${{ secrets.UPDATE_TOKEN }}" | |
- name: GITHUB_COMMIT_SHA | |
value: ${{ env.COMMIT_SHA }} | |
ports: | |
- containerPort: 8080 | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: killedby-latest | |
namespace: killedby-latest | |
spec: | |
selector: | |
app: killedby-latest | |
ports: | |
- protocol: TCP | |
port: 80 | |
targetPort: 8080 | |
--- | |
apiVersion: networking.k8s.io/v1 | |
kind: Ingress | |
metadata: | |
name: killedby-latest | |
namespace: killedby-latest | |
annotations: | |
cert-manager.io/cluster-issuer: "letsencrypt" | |
kubernetes.io/ingress.class: traefik | |
ingress.kubernetes.io/whitelist-source-range: "192.168.0.0/16" | |
spec: | |
tls: | |
- hosts: | |
- latest.killedby.bacherik.de | |
secretName: killedby-latest-tls | |
rules: | |
- host: latest.killedby.bacherik.de | |
http: | |
paths: | |
- path: / | |
pathType: Prefix | |
backend: | |
service: | |
name: killedby-latest | |
port: | |
number: 80 | |
EOF | |
- name: Deploy to Kubernetes | |
uses: actions-hub/[email protected] | |
env: | |
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} | |
with: | |
args: apply -f k8s/ |