Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eliecharra committed Mar 6, 2024
0 parents commit ebd2314
Show file tree
Hide file tree
Showing 8 changed files with 142 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
41 changes: 41 additions & 0 deletions app/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

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

func readSecret() string {
f, err := os.Open("/secrets/RANDOM_STRING")
if err != nil {
return ""
}
data, err := io.ReadAll(f)
if err != nil {
return ""
}
return string(data)
}

func main() {
listenAddr := ":8888"
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
}
resp := fmt.Sprintf("RANDOM_STRING=%s", readSecret())
_, _ = writer.Write([]byte(resp))
})
log.Printf("Listening on %s\n", listenAddr)
if err := http.ListenAndServe(listenAddr, nil); err != nil {
if !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
}
}
29 changes: 29 additions & 0 deletions infra/app/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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
name: demo
ports:
- containerPort: 8888
name: demo-port
volumeMounts:
- name: secrets
mountPath: /etc/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
10 changes: 10 additions & 0 deletions infra/app/spacelift.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: app.spacelift.io/v1beta1
kind: Run
spec:
stackName: spacelift-operator-demo
metadata:
name: spacelift-operator-demo
annotations:
argocd.argoproj.io/hook: Sync
argocd.argoproj.io/sync-wave: "-1"
9 changes: 9 additions & 0 deletions infra/tf/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "random_string" "random" {
length = 12
special = true
}

output "RANDOM_STRING" {
value = random_string.random.result
sensitive = true
}

0 comments on commit ebd2314

Please sign in to comment.