Add deployment pipeline and add some content
All checks were successful
/ docker-image (push) Successful in 1m31s
/ deployment (push) Successful in 0s

This commit is contained in:
Aaron Fischer 2023-09-28 10:13:41 +02:00 committed by Aaron Fischer
parent 58cfc5d312
commit e6e8aadd7c
9 changed files with 206 additions and 0 deletions

View file

@ -0,0 +1,49 @@
on:
push:
branches:
- main
jobs:
docker-image:
runs-on: docker
steps:
- name: Install dependencies
run: |
echo deb http://deb.debian.org/debian bullseye-backports main | tee /etc/apt/sources.list.d/backports.list
apt-get update -qq
apt-get install -y git
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -qq -y -t bullseye-backports docker.io
- name: Checkout the sourcecode
uses: actions/checkout@v3
- name: Set up Docker build environment (rootless)
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:v0.12.1-rootless
network=host
- name: Login to forgejo docker registry
uses: docker/login-action@v3
with:
registry: git.okoyono.de
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
- name: Build and push the docker image
uses: docker/build-push-action@v5
with:
push: true
tags: git.okoyono.de/okoyono-intern/okospaceapi:latest
deployment:
runs-on: self-hosted
steps:
# As an alternative, we could connect to the server via ssh and execute the
# script directly, but I like the webhook thing much more, because it is
# so much more versatile.
- name: Deploy via webhook
run: |
apk add curl
curl -v -X GET "http://host.docker.internal:8100?token=${{ secrets.DEPLOY_TOKEN }}&script=deploy-spaceapi.sh"

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/spaceapi-schema.json
/pkg/spaceapi/

14
Dockerfile Normal file
View file

@ -0,0 +1,14 @@
FROM golang:alpine AS build
COPY . /app
WORKDIR /app
RUN apk add --no-cache bash wget
RUN ./generate-spaceapi-types.sh
RUN GOOS=linux go build -o oko-spaceapi cmd/server.go
FROM alpine
WORKDIR /app
COPY --from=build /app/oko-spaceapi /app/oko-spaceapi
EXPOSE 8080
CMD ["/app/oko-spaceapi"]

View file

@ -1,2 +1,8 @@
# spaceapi
# Build/Use
```
go generate
go run cmd/server.go
```

103
cmd/server.go Normal file
View file

@ -0,0 +1,103 @@
package main
import (
"git.okoyono.de/oko-intern/okospaceapi/pkg/spaceapi"
"net/http"
)
//go:generate ../generate-spaceapi-types.sh
func main() {
definition := spaceapi.Root{
// TODO: Fill up with stuff
ApiCompatibility: []string{"14"},
Space: "økoyono",
Url: "https://okoyono.de/",
Contact: &spaceapi.Contact{
Email: "oko@datenhalter.de", // TODO: Better email
Mastodon: "@f@social.okoyono.de", // TODO: Replace with real handle
Matrix: "#public:matrix.okoyono.de",
},
Location: &spaceapi.Location{
Lat: 0.0, // TODO: Fill with cool coordinates
Lon: 0.0, // TODO: Fill with cool coordinates
Timezone: "Europe/Berlin",
},
Logo: "https://okoyono.de/images/ant.svg",
Links: []*spaceapi.LinksItems{
{
Description: "Website",
Name: "website",
Url: "https://okoyono.de",
},
{
Description: "Forgejo (Sourcecode)",
Name: "forgejo",
Url: "https://git.okoyono.de",
},
{
Description: "Mastodon (Social Media)",
Name: "mastodon",
Url: "https://social.okoyono.de",
},
{
Description: "OwnCast (Tube)",
Name: "owncast",
Url: "https://tube.okoyono.de",
},
{
Description: "SearXNG (Search)",
Name: "searxng",
Url: "https://search.okoyono.de",
},
{
Description: "Etherpad (pad)",
Name: "etherpad",
Url: "https://pad.okoyono.de",
},
{
Description: "Jitsi (Videochat)",
Name: "jitsi",
Url: "https://meet.okoyono.de",
},
},
Projects: []string{
"https://buchdesmonats.okoyono.de/",
"https://comicdesmonats.okoyono.de/",
"https://git.okoyono.de/okoyono/weatherstation",
},
Sensors: &spaceapi.Sensors{
TotalMemberCount: []*spaceapi.TotalMemberCountItems{
{
Description: "We are a small group of people from south Germany, meeting remote on a regular basis.",
Location: "Remote",
Value: 6,
},
},
//Temperature: []*spaceapi.TemperatureItems{
// {
// Location: "@f",
// Name: "weatherstatiøn",
// Description: "Weatherstatiøn located at @f.",
// Value: sensors.TemperatureF(),
// },
//},
},
}
json, err := definition.MarshalJSON()
if err != nil {
panic(err)
}
err = http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, err := w.Write(json)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}))
if err != nil {
panic(err)
}
}

8
docker-compose.yaml Normal file
View file

@ -0,0 +1,8 @@
version: "3"
services:
spaceapi:
build: .
restart: always
ports:
- "8080:8080"

15
generate-spaceapi-types.sh Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
script="$(realpath "${BASH_SOURCE[-1]}")"
path="$(dirname "$script")"
cd $path
wget -O spaceapi-schema.json https://raw.githubusercontent.com/SpaceApi/schema/master/14.json
go install github.com/a-h/generate/cmd/schema-generate@latest
mkdir -p pkg/spaceapi
/go/bin/schema-generate -o pkg/spaceapi/spaceapi.go -p spaceapi spaceapi-schema.json
rm spaceapi-schema.json
# TODO: Do it inline
# https://github.com/a-h/generate/blob/master/cmd/schema-generate/main.go

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module git.okoyono.de/oko-intern/okospaceapi
go 1.21.1

6
pkg/sensors/wind.go Normal file
View file

@ -0,0 +1,6 @@
package sensors
func TemperatureF() float64 {
// TODO: Fetch from influxdb (or remove influxdb finally!)
return 23.0
}