Golang / Singularity / gitlab
Menu
singularity を動かす
ssh amane % singularity shell --shell /bin/zsh /mnt/ie-virsh/singularity/os_complete/os_complete.sif
環境変数
zshrc などに設定する
VSCode
singularity の中で VSCode を動かすのは、ちょっと難しいできるならやってみて。
Project を作成する
FileWrite2 というプロジェクトを作る% mkdir ~/src/go/fileWrite2 % cd ~/src/go/fileWrite2 % mod init ie.u-ryukyu.ac.jp/teacher/kono/os/fileWrite2 % go mod tidy % go run main.gohello.go
package main import ( "fmt" ) func main() { fmt.Println("Hello, World!") }
先に gitlab で空のProjectを作る
group os/2023 の下の e215788-go-filewrite という名前で Project を作る
あとから gitlab に登録する
git init git add git commitする。gitlabのprojectを作って
git remote add orign git@gitlab.ie.u-ryukyu.ac.jp:os/2023/kono-go-01.git git push -uf origin mainとする。(https: は使えないので ssh を使う)
go を走らせる
main.go をそこに作る
package main import ( "fmt" "gitlab.ie.u-ryukyu.ac.jp/os/2021/kono-filewrite2/fileWrite" ) func main() { fmt.Println("Hello, World!") fmt.Println( fileWrite.Hello("kono")) }fileWrite/fileWrite.go を作る
package fileWrite import "fmt" // Hello returns a greeting for the named person. func Hello(name string) string { // Return a greeting that embeds the name in a message. message := fmt.Sprintf("Hi, %v. Welcome!", name) return message }で、
go run main.goする。
test
go testでテストできるように main_test.go を書く。
package main import ( "ie.u-ryukyu.ac.jp/teacher/kono/os/fileWrite2/fileIO" "testing" ) func Test_getOpts(t *testing.T) { type args struct { u fileIO.FileIO } // u1 := fileIO.FileIO{} var tests = []struct { name string args args }{ {"test", args{fileIO.FileIO{"fileName", false, 1024, 1024}}}, // {"test", args{fileIO.FileIO{"", false, 1024, 1024}}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { getOpts(& tt.args.u) if tt.args.u.FileName == "" { t.Fail() } }) } } func Test_sub1(t *testing.T) { tests := []struct { name string }{ // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { }) } }
gitlab CI/CD
今年は gitlab の CI/CD を使います。
Project に .gitlab-ci.yml を以下の内容で追加して、git push します。
image: golang:latest stages: - test - build - deploy format: stage: test script: - go fmt $(go list ./... | grep -v /vendor/) - go vet $(go list ./... | grep -v /vendor/) - go test -race $(go list ./... | grep -v /vendor/) compile: stage: build script: - mkdir -p mybinaries - go build -o mybinaries ./... artifacts: paths: - mybinaries成功したのと失敗した version の consle のURLを含めて提出します。