Hi! We are really excited that you are interested in contributing to CasaOS. Before submitting your contribution, please make sure to take a moment and read through the following guidelines.
(fix #xxxx[,#xxxx])
(#xxxx
is the issue id) in your PR title for a better release log, e.g. update entities encoding/decoding (fix #3899)
.The setup below is not the only way to get started on CasaOS development. Feel free to apply any experience and practices you are more comfortable with.
Download from https://go.dev/dl/
Extract go
directory and move to $HOME/.local/go
(or any directory you like)
Ensure ~/.profile
contains following line at the bottom(or place with the directory you selected in previous step)
PATH="$HOME/.local/go/bin:$HOME/go/bin:$PATH"
The two paths differ as follow
$HOME/.local/go
- Go root path, contains core, docs and libaries of Go$HOME/go
- Go tool path, contains tools and dependenciesMake sure go version
returns
Install goreleaser
- (one time)
go install github.com/goreleaser/goreleaser@latest
Install compilers - (one time)
sudo apt-get --no-install-recommends install upx \
gcc libc6-dev-amd64-cross \
gcc-aarch64-linux-gnu libc6-dev-arm64-cross \
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
Install https://code.visualstudio.com/
Install extensions
Make sure following setting is in the VSCode settings.json
{
"go.goroot": "~/.local/go",
"go.gopath": "~/go"
}
The two paths differ as follow
go.goroot
- Go root path, contains core, docs and libaries of Gogo.gopath
- Go tool path, contains tools and dependenciesAdditional recommended settings (but not required)
{
"git.autofetch": "all",
"go.delveConfig": {
"showGlobalVariables": true,
},
"go.diagnostic.vulncheck": "Imports",
"go.inlayHints.assignVariableTypes": true,
"go.inlayHints.compositeLiteralFields": true,
"go.inlayHints.compositeLiteralTypes": true,
"go.inlayHints.constantValues": true,
"go.inlayHints.functionTypeParameters": true,
"go.inlayHints.parameterNames": true,
"go.inlayHints.rangeVariableTypes": true,
"go.lintFlags": [
"-D",
"staticcheck",
"-E",
"gocyclo,gosec,makezero,prealloc,revive,usestdlibvars"
],
"go.lintTool": "golangci-lint",
"go.lintOnSave": "workspace",
"go.toolsManagement.autoUpdate": true,
"gopls": {
"formatting.gofumpt": true,
"ui.diagnostic.analyses": {
"fieldalignment": true,
"nilness": true,
"shadow": true,
"unusedparams": true,
"unusedvariable": true,
"unusedwrite": true,
"useany": true,
},
"ui.semanticTokens": true,
"ui.diagnostic.staticcheck": true,
},
}
These settings can greatly help productivity of Golang coding.
gofmt
.Install git
sudo apt-get --no-install-recommends install git
Clone following repositories
git clone git@github.com:IceWhaleTech/CasaOS-Common.git
git clone git@github.com:IceWhaleTech/CasaOS-CLI.git
git clone git@github.com:IceWhaleTech/CasaOS-Gateway.git
git clone git@github.com:IceWhaleTech/CasaOS-MessageBus.git
git clone git@github.com:IceWhaleTech/CasaOS-UserService.git
git clone git@github.com:IceWhaleTech/CasaOS-LocalStorage.git
git clone git@github.com:IceWhaleTech/CasaOS-AppManagement.git
git clone git@github.com:IceWhaleTech/CasaOS.git
Create a VSCode Workspace of all repositories
You can either manually add each repository one by one in the VSCode UI, or create a
.code-workspace
file at the common path like below.
$ cat CasaOS.code-workspace
{
"folders": [
{
"path": "CasaOS-Common"
},
{
"path": "CasaOS-CLI"
},
{
"path": "CasaOS-Gateway"
},
{
"path": "CasaOS-MessageBus"
},
{
"path": "CasaOS-UserService"
},
{
"path": "CasaOS-LocalStorage"
},
{
"path": "CasaOS-AppManagement"
},
{
"path": "CasaOS"
},
{
"path": "get"
}
],
"settings": {}
}
Open any main.go
and install Go
related tools when prompted
Try to build a binary
Taking CasaOS-LocalStorage for example here.
Run under path ./CasaOS-LocalStorage
goreleaser build --clean --snapshot -f .goreleaser.debug.yaml --id casaos-local-storage-amd64
Verify it is built fine
$ dist/casaos-local-storage-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-local-storage -v
v0.3.7
Try to build packages for all architectures
goreleaser release --clean --snapshot
Install official CasaOS as base setup - (one time)
curl -fsSL get.casaos.io | sudo bash
Visit http://localhost to verify
Stop corresponding service of whose code you would like to work on - because you will run it manually as part of debugging.
Start debugger adapter
You could debug the code directly like in any other regular Golang coding.
However because CasaOS requires root permission for certain features, like controlling systemd daemons, formatting harddrives, etc., we use this approach to place a wrapper under
sudo
so we can run our code under root permission later.
sudo $HOME/go/bin/dlv dap --listen=:2345 --only-same-user=false
Make your changes to the code and build the binary
goreleaser build --clean --snapshot -f .goreleaser.debug.yaml --id casaos-local-storage-amd64
Create launch.json
for each module - (one time)
Taking CasaOS-LocalStorage for example here.
It launches the built binary from previous step under the debugger adapter, the wrapper, we setup earlier due to potential need of root permission.
{
"version": "0.2.0",
"configurations": [
{
"name": "LocalStorage (localhost)",
"type": "go",
"debugAdapter": "dlv-dap",
"request": "launch",
"port": 2345,
"host": "127.0.0.1",
"mode": "exec",
"program": "${workspaceFolder}/dist/casaos-local-storage-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-local-storage"
}
]
}
Start debugging in VSCode
Hit Ctrl-Shift-D, then select LocalStorage (localhost) and hit F5
To verify the debug is running fine, set breakpoint at any place then trigger the corresponding logic and see if it is hit.