Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 188 additions & 10 deletions docs/organizations/companies/suse/archive/hobbyfarm.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# HobbyFarm
# HobbyFarm

> Hobbyfarm is an interactive coding platform that runs in the browser

Expand All @@ -11,10 +11,10 @@

### Technologies

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

### Code repositories

Expand All @@ -30,16 +30,194 @@ Name | Conten

### Local setup

* Start [Gargantua](https://github.com/hobbyfarm/gargantua/blob/master/CONTRIBUTING.md)
* Start Admin UI
* TODO
- Start [Gargantua](https://github.com/hobbyfarm/gargantua/blob/master/CONTRIBUTING.md)
- Start Admin UI
- TODO

## Operations

### Installation

* [Documentation](https://hobbyfarm.github.io/docs/setup/installation/)
- [Documentation](https://hobbyfarm.github.io/docs/setup/installation/)

## References

* [Amazon EC2](https://aws.amazon.com/ec2/)
- [Amazon EC2](https://aws.amazon.com/ec2/)

## 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

```bash
go version
```

- Build the application

```bash
go build
```

- Start local Kubernetes cluster

```bash
k3d cluster create hobbyfarm --api-port 6550 -p "8081:80@loadbalancer" -p "8082:443@loadbalancer" --agents 1
```

- Create manifest files:

```yaml
---
# 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

```bash
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
```

- Create CA and TLS files (see [How To Create CA and Generate SSL/TLS Certificates & Keys](https://scriptcrunch.com/create-ca-tls-ssl-certificates-keys/))

```bash
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

```bash
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](https://github.com/hobbyfarm/hobbyfarm) to provide a local [kind](https://github.com/kubernetes-sigs/kind) cluster for CRDs.

Next, run:

```bash
# 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](http://localhost:16210)

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