Skip to content

Commit 733d330

Browse files
committed
chore(ops): test deployment to do k8s
1 parent 84953dc commit 733d330

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

.github/workflows/publish.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,23 @@ jobs:
3030
registry: ${{ env.REGISTRY }}
3131
username: ${{ github.actor }}
3232
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
# Install DO CLI
35+
- name: Install doctl
36+
uses: digitalocean/action-doctl@v2
37+
with:
38+
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
39+
40+
- name: Log in to DigitalOcean Container Registry with short-lived credentials
41+
run: doctl registry login --expiry-seconds 1200
42+
3343
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
3444
- name: Extract metadata (tags, labels) for Docker
3545
id: meta
3646
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
3747
with:
3848
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
39-
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
49+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages and the DO registry for k8s.
4050
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
4151
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
4252
- name: Build and push Docker image
@@ -46,3 +56,17 @@ jobs:
4656
push: true
4757
tags: ${{ steps.meta.outputs.tags }}
4858
labels: ${{ steps.meta.outputs.labels }}
59+
60+
deploy-to-cluster:
61+
steps:
62+
- name: Update deployment file
63+
run: TAG=$(echo $GITHUB_SHA | head -c7) && sed -i 's|<IMAGE>|${{ secrets.REGISTRY_NAME }}/${{ env.IMAGE_NAME }}:'${TAG}'|' $GITHUB_WORKSPACE/config/deployment.yml
64+
65+
- name: Save DigitalOcean kubeconfig with short-lived credentials
66+
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.CLUSTER_NAME }}
67+
68+
- name: Deploy to DigitalOcean Kubernetes
69+
run: kubectl apply -f $GITHUB_WORKSPACE/config/deployment.yml
70+
71+
- name: Verify deployment
72+
run: kubectl rollout status deployment/${{ env.IMAGE_NAME }}

config/deployment.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: services-proposals
5+
labels:
6+
app: services-proposals
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: services-proposals
12+
strategy:
13+
rollingUpdate:
14+
maxSurge: 1
15+
maxUnavailable: 1
16+
minReadySeconds: 5
17+
template:
18+
metadata:
19+
labels:
20+
app: services-proposals
21+
spec:
22+
containers:
23+
- name: services-proposals
24+
image: <IMAGE>
25+
ports:
26+
- containerPort: 80
27+
resources:
28+
requests:
29+
cpu: 100m
30+
limits:
31+
cpu: 100m
32+
---
33+
# apiVersion: v1
34+
# kind: Service
35+
# metadata:
36+
# name: services-proposals
37+
# spec:
38+
# type: LoadBalancer
39+
# ports:
40+
# - name: http
41+
# protocol: TCP
42+
# port: 80
43+
# targetPort: 80
44+
# selector:
45+
# app: services-proposals

0 commit comments

Comments
 (0)