Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added kustomize k8s deployment #2

Merged
merged 12 commits into from
Nov 7, 2023
2 changes: 2 additions & 0 deletions .github/workflows/release-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ jobs:
channel: 'Branches'
release_number: ${{ steps.branch-name.outputs.current_branch }}.${{ github.run_id }}
package_version: ${{ steps.branch-name.outputs.current_branch }}.${{ github.run_id }}
git_ref: ${{ (github.ref_type == 'tag' && github.event.repository.default_branch ) || (github.head_ref || github.ref) }}
git_commit: ${{ github.event.after || github.event.pull_request.head.sha }}
69 changes: 55 additions & 14 deletions .octopus/deployment_process.ocl
Original file line number Diff line number Diff line change
@@ -1,28 +1,69 @@
step "hello-world" {
name = "hello world"
step "kustomize" {
name = "Kustomize"
package_requirement = "AfterPackageAcquisition"
properties = {
Octopus.Action.TargetRoles = "shipped23-k8s"
}

action {
action_type = "Octopus.Script"
action_type = "kustomize"
properties = {
Octopus.Action.RunOnServer = "true"
Octopus.Action.Script.ScriptBody = <<-EOT
image=$(get_octopusvariable "Octopus.Action.Package[shipped23].Image")

echo "deploying image: $image"
EOT
Octopus.Action.Script.ScriptSource = "Inline"
Octopus.Action.Script.Syntax = "Bash"
OctopusUseBundledTooling = "False"
}
step_package_version = "2.0.2"
worker_pool = "hosted-ubuntu"

container {
feed = "dockerhub"
image = "octopuslabs/k8s-workertools:1.28.2-ubuntu.2204"
}

git_dependencies {
default_branch = "k8s"
git_credential_id = "GitCredentials-1"
git_credential_type = "Library"
repository_uri = "https://github.com/MJRichardson/shipped23.git"
step_package_inputs_reference_id = "a135779e-9293-4bde-a625-640586cf16f6"
}

packages "shipped23" {
acquisition_location = "NotAcquired"
feed = "github-container-registry"
package_id = "mjrichardson/shipped23"
properties = {
Extract = "False"
Purpose = ""
SelectionMode = "immediate"
step_package_inputs_reference_id = "fd9cee07-c687-41f7-9454-73822da130d7"
}

inputs {
overlayPath = "deploy/kustomize/octopus"

containerImageReferences {
containerImageReference {
feedId = "Feeds-1467"
imageName = "mjrichardson/shipped23"
referenceId = "fd9cee07-c687-41f7-9454-73822da130d7"
}
}

gitSource {
defaultBranch = "k8s"
gitCredential = "GitCredentials-1"
isAnonymous = false
referenceId = "a135779e-9293-4bde-a625-640586cf16f6"
url = "https://github.com/MJRichardson/shipped23.git"
}

kubernetesObjectStatus {
enabled = true
timeout = 180
waitForJobs = false
}

substituteFiles {
filesToTarget = <<-EOT
deploy/kustomize/octopus/.env
deploy/kustomize/octopus/*.yaml
EOT
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions .octopus/variables.ocl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "Kubernetes.Namespace" {
value "shipped-#{Octopus.Release.Git.BranchName}" {}
}
23 changes: 23 additions & 0 deletions deploy/kustomize/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: shipped23-deployment
labels:
app: shipped23
spec:
selector:
matchLabels:
app: shipped23
replicas: 1
strategy:
type: RollingUpdate
template:
metadata:
labels:
app: shipped23
spec:
containers:
- name: shipped23
image: shipped23:latest
ports:
- containerPort: 8080
4 changes: 4 additions & 0 deletions deploy/kustomize/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resources:
- namespace.yaml
- deployment.yaml
- service.yaml
4 changes: 4 additions & 0 deletions deploy/kustomize/base/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: shipped23
11 changes: 11 additions & 0 deletions deploy/kustomize/base/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: shipped23
spec:
type: LoadBalancer
selector:
app: shipped23
ports:
- port: 8080
targetPort: 8080
3 changes: 3 additions & 0 deletions deploy/kustomize/octopus/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
environment=#{Octopus.Environment.Name}
branch=#{Octopus.Release.Git.BranchName}
sha=#{Octopus.Release.Git.CommitHash}
10 changes: 10 additions & 0 deletions deploy/kustomize/octopus/image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: shipped23
spec:
template:
spec:
containers:
- name: shipped23
image: "#{Octopus.Action.Package[shipped23].Image}"
7 changes: 7 additions & 0 deletions deploy/kustomize/octopus/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace: "#{Kubernetes.Namespace}"
resources:
- ../base
patches:
- path: image.yaml
target:
kind: Deployment