Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eliecharra committed Mar 11, 2024
0 parents commit 4155a87
Show file tree
Hide file tree
Showing 19 changed files with 396 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build docker image
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ./app
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/spacelift-io/spacelift-operator-demo:latest
ghcr.io/spacelift-io/spacelift-operator-demo:${{ github.sha }}
11 changes: 11 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.21.7 as builder
WORKDIR /build
COPY . .
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o demo .

FROM scratch
COPY --from=builder /build/demo /bin/demo
ENTRYPOINT ["/bin/demo"]



3 changes: 3 additions & 0 deletions app/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/spacelift-io/spacelift-operator-demo

go 1.21.7
32 changes: 32 additions & 0 deletions app/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"errors"
"fmt"
"log"
"net/http"
"os"
)

func main() {
listenAddr := ":80"
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
log.Println(request.Method, request.URL.String())
if request.URL.Path != "/" {
writer.WriteHeader(http.StatusNotFound)
return
}
secrets := os.Environ()
body := ""
for i := 0; i < len(secrets)-1; i = i + 2 {
body += fmt.Sprintf("%s=%s\n", secrets[i], secrets[i+1])
}
_, _ = writer.Write([]byte(body))
})
log.Printf("Listening on %s\n", listenAddr)
if err := http.ListenAndServe(listenAddr, nil); err != nil {
if !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
}
}
30 changes: 30 additions & 0 deletions infra/app/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo
spec:
replicas: 1
revisionHistoryLimit: 3
selector:
matchLabels:
app: demo
template:
metadata:
labels:
app: demo
spec:
containers:
- image: ghcr.io/spacelift-io/spacelift-operator-demo:latest
imagePullPolicy: Always
name: demo
ports:
- containerPort: 80
name: demo-port
volumeMounts:
- name: secrets
mountPath: /secrets
readOnly: true
volumes:
- name: secrets
secret:
secretName: stack-output-spacelift-operator-demo
10 changes: 10 additions & 0 deletions infra/app/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: demo
spec:
ports:
- port: 80
targetPort: demo-port
selector:
app: demo
37 changes: 37 additions & 0 deletions infra/app/spacelift.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: app.spacelift.io/v1beta1
kind: Stack
metadata:
name: demo-stack
annotations:
argocd.argoproj.io/sync-wave: "-2"
spec:
name: spacelift-operator-demo
commitSHA: 37ecb7856840b8336b6b9e163472ef844c8d9800
settings:
administrative: false
space: spacelift-operator-01HR9KQ590MFT6H6ETFJ657KR6
namespace: spacelift-io
repository: spacelift-operator-demo
projectRoot: infra/tf
branch: main
managesStateFile: true
awsIntegration:
id: 01HRQ4YMJQTP5R6K8Q9N1NB3XM
read: true
write: true
vendorConfig:
terraform:
version: 1.6.2
workflowTool: OPEN_TOFU
labels:
- argo
---
apiVersion: app.spacelift.io/v1beta1
kind: Run
metadata:
name: spacelift-operator-demo
annotations:
argocd.argoproj.io/hook: Sync
argocd.argoproj.io/sync-wave: "-1"
spec:
stackName: demo-stack
23 changes: 23 additions & 0 deletions infra/helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions infra/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: operator-demo
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.0.0"
47 changes: 47 additions & 0 deletions infra/helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "operator-demo.name" -}}
{{- default .Chart.Name | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "operator-demo.fullname" -}}
{{- $name := default .Chart.Name }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "operator-demo.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "operator-demo.labels" -}}
helm.sh/chart: {{ include "operator-demo.chart" . }}
{{ include "operator-demo.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "operator-demo.selectorLabels" -}}
app.kubernetes.io/name: {{ include "operator-demo.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
31 changes: 31 additions & 0 deletions infra/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "operator-demo.fullname" . }}
labels:
{{- include "operator-demo.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "operator-demo.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "operator-demo.labels" . | nindent 8 }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
envFrom:
- secretRef:
name: stack-output-spacelift-operator-demo
15 changes: 15 additions & 0 deletions infra/helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "operator-demo.fullname" . }}
labels:
{{- include "operator-demo.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "operator-demo.selectorLabels" . | nindent 4 }}
6 changes: 6 additions & 0 deletions infra/helm/templates/spacelift/run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: app.spacelift.io/v1beta1
kind: Run
metadata:
name: run-{{ .Values.image.tag }}
spec:
stackName: {{ .Values.spacelift.stack.name }}
9 changes: 9 additions & 0 deletions infra/helm/templates/spacelift/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: app.spacelift.io/v1beta1
kind: Stack
metadata:
name: {{ .Values.spacelift.stack.name }}
spec:
name: {{ .Values.spacelift.stack.name }}
commitSHA: {{ .Values.image.tag }}
settings:
{{- toYaml .Values.spacelift.stack.settings | nindent 4 }}
37 changes: 37 additions & 0 deletions infra/helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
replicaCount: 1
image:
repository: ghcr.io/spacelift-io/spacelift-operator-demo
pullPolicy: IfNotPresent
tag: ""
service:
type: ClusterIP
port: 80
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
spacelift:
stack:
name: spacelift-operator-demo
settings:
administrative: false
space: spacelift-operator-01HR9KQ590MFT6H6ETFJ657KR6
namespace: spacelift-io
repository: spacelift-operator-demo
projectRoot: infra/tf
branch: main
managesStateFile: true
awsIntegration:
id: 01HRQ4YMJQTP5R6K8Q9N1NB3XM
read: true
write: true
vendorConfig:
terraform:
version: 1.6.2
workflowTool: OPEN_TOFU
labels:
- argo
36 changes: 36 additions & 0 deletions infra/tf/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions infra/tf/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "BUCKET_URL" {
value = "https://${aws_s3_bucket.bucket.bucket_regional_domain_name}"
}
Loading

0 comments on commit 4155a87

Please sign in to comment.