Skip to main content

HobbyFarm

Hobbyfarm is an interactive coding platform that runs in the browser

🌐 hobbyfarm.github.io, docs, organization, issues

Software design

Technologies

  • Front-end: Angular
  • Back-end: Go
  • Documentation: Markdown
  • Website: Hugo

Code repositories

NameContent
admin-uiHobbyFarm administration UI (web application)
ec2-operatorAmazon EC2 operator for HobbyFarm
gargantuaHobbyFarm back-end (monolith application)
hfcliHobbyFarm Command Line Interface (CLI)
hobbyfarmHobbyFarm Helm chart
hobbyfarm.github.ioHobbyFarm documentation/website
uiHobbyFarm UI

Local setup

Operations

Installation

References

Contributing

Code logic

The application processing starts with main.go file at the root of the source files. All the other go code is located in pkg folder.

How it works:

  • Clients are TODO
  • Controllers are TODO
  • Servers define the REST API entry points (route,method -> action)
    • AuthServer
    • CourseServer
    • EnvironmentServer
    • ProgressServer
    • RbacServer
    • ScenarioServer
    • ScheduleEventServer
    • SessionServer
    • UserServer
    • VmServer
    • VmSetServer
    • VmTemplateServer

Local Development

  • Go 1.19 must be installed
go version
  • Build the application
go build
  • Start local Kubernetes cluster
k3d cluster create hobbyfarm --api-port 6550 -p "8081:80@loadbalancer" -p "8082:443@loadbalancer" --agents 1
  • Create manifest files:
---
# rolebindings.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: hobbyfarm-admin-rolebinding
subjects:
- kind: User
name: admin
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: hobbyfarm-admin
apiGroup: rbac.authorization.k8s.io
---
# roles.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: hobbyfarm-admin
rules:
- apiGroups: ["hobbyfarm.io"]
resources: ["*"]
verbs: ["*"]
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["roles", "rolebindings"]
verbs: ["*"]
---
# users.yaml
apiVersion: hobbyfarm.io/v1
kind: User
metadata:
name: admin
spec:
id: admin
email: admin
password: $2a$10$33fQs0G.lHQdDAsdoECgA.8iYvNtyJ2XC2AmvR5x6ZkzxSuKXyfFm
access_codes:
- training
settings:
ctr_enabled: "true"
ctxAccessCode: example-access-code
terminal_fontSize: "16"
terminal_theme: Solarized_Dark_Higher_Contrast
  • Define Kubernetes objects needed by HobbyFarm
kubectl create ns hobbyfarm
kubectl apply -f samples/kubernetes/roles.yaml -n hobbyfarm
kubectl apply -f samples/kubernetes/users.yaml -n hobbyfarm
kubectl apply -f samples/kubernetes/rolebindings.yaml -n hobbyfarm
cd .ssl/
openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes \
-key ca.key -subj "/CN=hobbyfarm/C=US/L=CALIFORNIA" \
-days 1825 -out ca.crt
openssl genrsa -out server.key 2048
cat > csr.conf <<EOF
[ req ]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn

[ dn ]
C = US
ST = California
L = San Fransisco
O = HobbyFarm
OU = HobbyFarm Dev
CN = hobbyfarm.github.io

[ req_ext ]
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = hobbyfarm
DNS.2 = hobbyfarm.dev.local
EOF
openssl req -new -key server.key -out server.csr -config csr.conf
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \
-CAcreateserial -out server.crt -days 10000 \
-extfile csr.conf
cd ..
  • Run the application
go run . --kubeconfig=%userprofile%\.kube\config --webhook-tls-cert=.ssl/server.crt --webhook-tls-key=.ssl/server.key -webhook-tls-ca=.ssl/ca.crt -logtostderr -v=9 -nowebwookcall=true

Local Development via docker-compose

First, start the docker-compose stack in hobbyfarm/hobbyfarm to provide a local kind cluster for CRDs.

Next, run:

# create or start stack
./compose.sh up

# -- or --
# start the stack, building changes to local dev container
# only needed if a file in ./cicd/docker-local has changed
./compose.sh up --build

# stop stack
./compose.sh stop

# destroy stack
./compose.sh destroy

The script ./compose-up.sh does the following:

  • connects to the external docker network hobbyfarm-dev
  • mounts the external volume for kube service account credentials called hobbyfarm-kube-sa
  • calls docker-compose up
    • creates or starts the hf-garg container, which runs a watch loop on golang files, re-builds on change, and listens on localhost:16210

To modify docker-compose variables for your local environment, copy .env.example to .env and update variables as needed.