-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (78 loc) · 2.75 KB
/
deploy.yml
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
name: Build Container & Deploy to K8s
on:
push:
branches:
- main
paths:
- bin/**
- site/**
- Containerfile
jobs:
# Build the container
build-container:
name: Build Container
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/kenmoini/kenmoini.com
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,prefix=,suffix=,format=short
type=sha,prefix=,suffix=,format=long
type=raw,value=latest
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: "${{ secrets.REGISTRY_USERNAME }}"
password: "${{ secrets.REGISTRY_TOKEN }}"
#- name: Install doctl
# uses: digitalocean/action-doctl@v2
# with:
# token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
file: ./Containerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: pass environment
uses: appleboy/[email protected]
env:
KUBECONFIG: "~/.kube/config"
GIT_SHA: ${{ github.sha }}
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
envs: KUBECONFIG,GIT_SHA
script: |
cd /opt/kenmoini.com/deploy/k3s
git pull
cp overlays/image-patch/kustomization.yml overlays/image-patch/kustomization.yml.bak
TAG=$(echo $GIT_SHA | head -c7) && sed -i 's|PATCH_ME|:'${TAG}'|' overlays/image-patch/kustomization.yml
kubectl apply -k overlays/image-patch
mv overlays/image-patch/kustomization.yml.bak overlays/image-patch/kustomization.yml
#- name: Save DigitalOcean kubeconfig with short-lived credentials
# run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.DO_CLUSTER_ID }}
#- name: Update deployment file
# run: TAG=$(echo $GITHUB_SHA | head -c7) && sed -i 's|:latest|:'${TAG}'|' $GITHUB_WORKSPACE/deploy/k8s/02-deployment.yaml
#- name: Deploy to DigitalOcean Kubernetes
# run: kubectl apply -f $GITHUB_WORKSPACE/deploy/k8s/