Skip to content

Commit

Permalink
chore(ops): test deployment to do k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
zenlex committed Mar 17, 2024
1 parent 84953dc commit 733d330
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
26 changes: 25 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,23 @@ jobs:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Install DO CLI
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 1200

# 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.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# 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.
# 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.
# 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.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
Expand All @@ -46,3 +56,17 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

deploy-to-cluster:
steps:
- name: Update deployment file
run: TAG=$(echo $GITHUB_SHA | head -c7) && sed -i 's|<IMAGE>|${{ secrets.REGISTRY_NAME }}/${{ env.IMAGE_NAME }}:'${TAG}'|' $GITHUB_WORKSPACE/config/deployment.yml

- name: Save DigitalOcean kubeconfig with short-lived credentials
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.CLUSTER_NAME }}

- name: Deploy to DigitalOcean Kubernetes
run: kubectl apply -f $GITHUB_WORKSPACE/config/deployment.yml

- name: Verify deployment
run: kubectl rollout status deployment/${{ env.IMAGE_NAME }}
45 changes: 45 additions & 0 deletions config/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: services-proposals
labels:
app: services-proposals
spec:
replicas: 1
selector:
matchLabels:
app: services-proposals
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
app: services-proposals
spec:
containers:
- name: services-proposals
image: <IMAGE>
ports:
- containerPort: 80
resources:
requests:
cpu: 100m
limits:
cpu: 100m
---
# apiVersion: v1
# kind: Service
# metadata:
# name: services-proposals
# spec:
# type: LoadBalancer
# ports:
# - name: http
# protocol: TCP
# port: 80
# targetPort: 80
# selector:
# app: services-proposals

0 comments on commit 733d330

Please sign in to comment.