Skip to content

Commit

Permalink
Actually deploy to K8s now (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelicianoTech authored Oct 23, 2023
1 parent 97c2de1 commit 89ec3f3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
71 changes: 69 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ version: 2.1

orbs:
gor: hubci/goreleaser@2.4
k8s: circleci/kubernetes@1.3

executors:
linux:
machine:
image: ubuntu-2204:2023.07.2

workflows:
main-wf:
Expand All @@ -15,12 +21,23 @@ workflows:
name: goreleaser-snapshot
version: *goreleaser-version
go-version: *go-version
image: linux
dry-run: true
pre-steps:
- run: echo $GITHUB_TOKEN | docker login ghcr.io -u felicianotech --password-stdin
post-steps:
- when:
condition:
equal: [ "<< pipeline.git.branch >>", "trunk" ]
steps:
- run: docker push --all-tags ghcr.io/cloud-unpacked/ippi
- persist_to_workspace:
root: "."
paths:
- "dist"
context:
- docker-ctx
- goreleaser-ctx
release-wf:
jobs:
- test:
Expand All @@ -31,16 +48,32 @@ workflows:
# SemVer regex
only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
- gor/release:
name: goreleaser-publish
name: release-with-goreleaser
version: *goreleaser-version
go-version: *go-version
image: linux
filters: *semverFilters
pre-steps:
- run: echo $GITHUB_TOKEN | docker login ghcr.io -u felicianotech --password-stdin
post-steps:
- persist_to_workspace:
root: "."
paths:
- "dist"
- "."
context: goreleaser-ctx
- deploy:
name: "deploy-prod"
environment: "production"
requires:
- release-with-goreleaser
filters:
branches:
ignore: /.*/
tags:
# Simplified SemVer regex
only: /^v\d+\.\d+\.\d+$/
context:
- k8s-ctx

jobs:
test:
Expand All @@ -61,3 +94,37 @@ jobs:
key: go-mod-v1
paths:
- "/go/pkg/mod"
deploy:
parameters:
environment:
description: "The server environment this should deploy to."
type: enum
enum:
- "production"
- "staging"
executor: linux
steps:
- attach_workspace:
at: .
- k8s/install-kubeconfig
- k8s/install-kubectl:
kubectl-version: "v1.27.6"
- run:
name: "Deploy"
command: |
# It's possible we're trying to deploy too fast. Wait 10 seconds
# before tryingt to deploy new images
sleep 10
if [ "<< parameters.environment >>" == "staging" ]; then
echo "Deploying to staging."
IMAGE=$(cat ./dist/artifacts.json | jq '.[].name | match("(^ghcr)(.*)(SNAPSHOT)(.*)$")' | jq -r .string)
kubectl set image --namespace=cloud-unpacked deployment/ippi app=$IMAGE
fi
if [ "<< parameters.environment >>" == "production" ]; then
echo "Deploying to production."
kubectl set image --namespace=cloud-unpacked deployment/ippi app=<< pipeline.git.tag >>
fi
7 changes: 7 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ nfpms:
- deb
bindir: /usr/bin

dockers:
- image_templates:
- "ghcr.io/cloud-unpacked/ippi:{{ .Version }}"
- "ghcr.io/cloud-unpacked/ippi:{{ if .IsSnapshot }}staging{{ else }}v{{ .Major }}.{{ .Minor }}{{ end }}"
- "ghcr.io/cloud-unpacked/ippi:latest"
dockerfile: goreleaser.Dockerfile

checksum:
name_template: "{{ .ProjectName }}-v{{ .Version }}-checksums.txt"

Expand Down
2 changes: 1 addition & 1 deletion k8s/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apiVersion: v1
kind: Service
metadata:
namespace: cloud-unpacked
name: webapp-production
name: ippi
labels:
app: ippi
spec:
Expand Down

0 comments on commit 89ec3f3

Please sign in to comment.