Skip to content

Commit 8f410a0

Browse files
authored
Add contributing in hobbyfarm (#4)
1 parent b7451b7 commit 8f410a0

1 file changed

Lines changed: 188 additions & 10 deletions

File tree

docs/organizations/companies/suse/archive/hobbyfarm.md

Lines changed: 188 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# HobbyFarm
1+
# HobbyFarm
22

33
> Hobbyfarm is an interactive coding platform that runs in the browser
44
@@ -11,10 +11,10 @@
1111

1212
### Technologies
1313

14-
* Front-end: Angular
15-
* Back-end: Go
16-
* Documentation: Markdown
17-
* Website: Hugo
14+
- Front-end: Angular
15+
- Back-end: Go
16+
- Documentation: Markdown
17+
- Website: Hugo
1818

1919
### Code repositories
2020

@@ -30,16 +30,194 @@ Name | Conten
3030

3131
### Local setup
3232

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

3737
## Operations
3838

3939
### Installation
4040

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

4343
## References
4444

45-
* [Amazon EC2](https://aws.amazon.com/ec2/)
45+
- [Amazon EC2](https://aws.amazon.com/ec2/)
46+
47+
## Contributing
48+
49+
### Code logic
50+
51+
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.
52+
53+
How it works:
54+
55+
- _Clients_ are TODO
56+
- _Controllers_ are TODO
57+
- _Servers_ define the REST API entry points (route,method -> action)
58+
- `AuthServer`
59+
- `CourseServer`
60+
- `EnvironmentServer`
61+
- `ProgressServer`
62+
- `RbacServer`
63+
- `ScenarioServer`
64+
- `ScheduleEventServer`
65+
- `SessionServer`
66+
- `UserServer`
67+
- `VmServer`
68+
- `VmSetServer`
69+
- `VmTemplateServer`
70+
71+
### Local Development
72+
73+
- Go 1.19 must be installed
74+
75+
```bash
76+
go version
77+
```
78+
79+
- Build the application
80+
81+
```bash
82+
go build
83+
```
84+
85+
- Start local Kubernetes cluster
86+
87+
```bash
88+
k3d cluster create hobbyfarm --api-port 6550 -p "8081:80@loadbalancer" -p "8082:443@loadbalancer" --agents 1
89+
```
90+
91+
- Create manifest files:
92+
93+
```yaml
94+
---
95+
# rolebindings.yaml
96+
apiVersion: rbac.authorization.k8s.io/v1
97+
kind: RoleBinding
98+
metadata:
99+
name: hobbyfarm-admin-rolebinding
100+
subjects:
101+
- kind: User
102+
name: admin
103+
apiGroup: rbac.authorization.k8s.io
104+
roleRef:
105+
kind: Role
106+
name: hobbyfarm-admin
107+
apiGroup: rbac.authorization.k8s.io
108+
---
109+
# roles.yaml
110+
apiVersion: rbac.authorization.k8s.io/v1
111+
kind: Role
112+
metadata:
113+
name: hobbyfarm-admin
114+
rules:
115+
- apiGroups: ["hobbyfarm.io"]
116+
resources: ["*"]
117+
verbs: ["*"]
118+
- apiGroups: ["rbac.authorization.k8s.io"]
119+
resources: ["roles", "rolebindings"]
120+
verbs: ["*"]
121+
---
122+
# users.yaml
123+
apiVersion: hobbyfarm.io/v1
124+
kind: User
125+
metadata:
126+
name: admin
127+
spec:
128+
id: admin
129+
email: admin
130+
password: $2a$10$33fQs0G.lHQdDAsdoECgA.8iYvNtyJ2XC2AmvR5x6ZkzxSuKXyfFm
131+
access_codes:
132+
- training
133+
settings:
134+
ctr_enabled: "true"
135+
ctxAccessCode: example-access-code
136+
terminal_fontSize: "16"
137+
terminal_theme: Solarized_Dark_Higher_Contrast
138+
```
139+
140+
- Define Kubernetes objects needed by HobbyFarm
141+
142+
```bash
143+
kubectl create ns hobbyfarm
144+
kubectl apply -f samples/kubernetes/roles.yaml -n hobbyfarm
145+
kubectl apply -f samples/kubernetes/users.yaml -n hobbyfarm
146+
kubectl apply -f samples/kubernetes/rolebindings.yaml -n hobbyfarm
147+
```
148+
149+
- 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/))
150+
151+
```bash
152+
cd .ssl/
153+
openssl genrsa -out ca.key 2048
154+
openssl req -x509 -new -nodes \
155+
-key ca.key -subj "/CN=hobbyfarm/C=US/L=CALIFORNIA" \
156+
-days 1825 -out ca.crt
157+
openssl genrsa -out server.key 2048
158+
cat > csr.conf <<EOF
159+
[ req ]
160+
default_bits = 2048
161+
prompt = no
162+
default_md = sha256
163+
req_extensions = req_ext
164+
distinguished_name = dn
165+
166+
[ dn ]
167+
C = US
168+
ST = California
169+
L = San Fransisco
170+
O = HobbyFarm
171+
OU = HobbyFarm Dev
172+
CN = hobbyfarm.github.io
173+
174+
[ req_ext ]
175+
subjectAltName = @alt_names
176+
177+
[ alt_names ]
178+
DNS.1 = hobbyfarm
179+
DNS.2 = hobbyfarm.dev.local
180+
EOF
181+
openssl req -new -key server.key -out server.csr -config csr.conf
182+
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \
183+
-CAcreateserial -out server.crt -days 10000 \
184+
-extfile csr.conf
185+
cd ..
186+
```
187+
188+
- Run the application
189+
190+
```bash
191+
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
192+
```
193+
194+
### Local Development via docker-compose
195+
196+
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.
197+
198+
Next, run:
199+
200+
```bash
201+
# create or start stack
202+
./compose.sh up
203+
204+
# -- or --
205+
# start the stack, building changes to local dev container
206+
# only needed if a file in ./cicd/docker-local has changed
207+
./compose.sh up --build
208+
209+
# stop stack
210+
./compose.sh stop
211+
212+
# destroy stack
213+
./compose.sh destroy
214+
```
215+
216+
The script `./compose-up.sh` does the following:
217+
218+
- connects to the external docker network `hobbyfarm-dev`
219+
- mounts the external volume for kube service account credentials called `hobbyfarm-kube-sa`
220+
- calls `docker-compose up`
221+
- 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)
222+
223+
To modify docker-compose variables for your local environment, copy `.env.example` to `.env` and update variables as needed.

0 commit comments

Comments
 (0)