multi os binary build
setup gox
gox라는 명령어를 이용할 것이다.
Gox - Simple Go Cross Compilation
다음 웹사이트를 참고하자.
https://github.com/mitchellh/gox
project 폴더에서 다음을 실행한다.
go get github.com/mitchellh/gox@v1.0.1go.mod에 내용이 추가된걸 확인할수 있다.
이제 ci/cd시에 이 프로젝트를 설치하게 해주면된다.
tools.go 추가
vi tools.go
//go:build tools
// +build tools
package main
// These imports are to force `go mod tidy` not to remove that tools we depend
// on development. This is explained in great detail in
// https://marcofranssen.nl/manage-go-tools-via-go-modules/
import (
_ "github.com/mitchellh/gox"
)build
make 파일을 사용해서 빌드를 해보자.
프로젝트에 Makefile을 만들자.
vi Makefile
clean -> setup -> build-binaries 로 동작한다.
make build-binaries를 하면 패키지를 빌드한다.
ci/cd setup
.gitlab-ci.yml
yaml yank를 이용해서 yaml을 줄엿다. 기본적으로는 *binaries에 위에 binary를 다 넣어주면 된다.
binaries darwin/amd64 이게 작업 이름인데 이것중요 darwin/amd64를 가져와서 그걸 make에 보내주면 make가 빌드를 하는 구조이다.
artifact를 이용하여 저장을 해두는것이다. 이렇게 해두면 ui에서 다운로드를 받을수 있다.

upload artifact to package & registries
vi .gitlab-ci.yml
아까 설정해둔 variable 을 사용한다.
for문을 돌면서 파일을 업로드한다.
실행하면 다음과 같이 패키지에 업로드 됨을 알수있다.


release
vi .gitlab-ci.yml
일단 git에 로그를 읽어와서 description이라는 환경변수 사용해야하므로 파일에 적어둔후 artifact에 추가해준다. 나중에 $DESCRIPTION 이러면 다른 작업에서 사용할수 있다.
이제 release를 생성하자 file은 링크로 잡아서 올려주면 된다.
다음처럼 release가 생긴것을 알수 있다.

완성
Last updated
Was this helpful?