-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (143 loc) · 4.17 KB
/
deploy.yml
File metadata and controls
158 lines (143 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Deploy Jekyll Site to K3s
on:
push:
branches: [ main, master ]
env:
REGISTRY: ci.gmac.io
IMAGE_NAME: mackieg/personalwebsite
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: false
- name: Install Jekyll
run: |
gem install jekyll bundler
bundle init
bundle add jekyll
- name: Build Jekyll site
run: |
bundle exec jekyll build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Gitea Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Deploy to K3s
env:
KUBECONFIG_CONTENT: ${{ secrets.KUBECONFIG }}
run: |
# Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
# Setup kubeconfig
echo "$KUBECONFIG_CONTENT" | base64 -d > /tmp/kubeconfig
export KUBECONFIG=/tmp/kubeconfig
# Create deployment manifest
cat <<EOF > deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: grahammackie-com
namespace: production
labels:
app: grahammackie-com
spec:
replicas: 2
selector:
matchLabels:
app: grahammackie-com
template:
metadata:
labels:
app: grahammackie-com
spec:
containers:
- name: nginx
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
ports:
- containerPort: 80
resources:
requests:
memory: "32Mi"
cpu: "10m"
limits:
memory: "128Mi"
cpu: "100m"
imagePullSecrets:
- name: gitea-registry
---
apiVersion: v1
kind: Service
metadata:
name: grahammackie-com
namespace: production
spec:
selector:
app: grahammackie-com
ports:
- port: 80
targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: grahammackie-com
namespace: production
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
ingressClassName: nginx
tls:
- hosts:
- grahammackie.com
- www.grahammackie.com
secretName: grahammackie-com-tls
rules:
- host: grahammackie.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: grahammackie-com
port:
number: 80
- host: www.grahammackie.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: grahammackie-com
port:
number: 80
EOF
# Apply deployment
kubectl apply -f deployment.yaml
# Wait for deployment
kubectl rollout status deployment/grahammackie-com \
-n production \
--timeout=300s
echo "✅ Jekyll site deployed to https://grahammackie.com"