Skip to content

Commit 22f5d06

Browse files
committed
Create apiserver binary and upload it to s3 bucket
Signed-off-by: Anil Vishnoi <[email protected]>
1 parent 05930ce commit 22f5d06

File tree

3 files changed

+164
-4
lines changed

3 files changed

+164
-4
lines changed

.github/workflows/api-server.yml

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@ on:
55
branches:
66
- main
77
- release-1.0
8+
paths:
9+
- 'api-server/**'
10+
811
pull_request:
912
branches:
1013
- main
1114
- release-1.0
15+
paths:
16+
- 'api-server/**'
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
20+
cancel-in-progress: true
1221

1322
jobs:
1423
fmt-build-test:
1524
runs-on: ubuntu-latest
16-
1725
env:
1826
CGO_ENABLED: 1
19-
2027
defaults:
2128
run:
2229
working-directory: api-server
@@ -47,7 +54,71 @@ jobs:
4754
echo "$unformatted"
4855
exit 1
4956
fi
50-
5157
- name: Build
5258
run: |
5359
go build ./...
60+
61+
build-packages:
62+
needs: [ fmt-build-test ]
63+
runs-on: ubuntu-latest
64+
defaults:
65+
run:
66+
working-directory: api-server
67+
68+
steps:
69+
- uses: actions/checkout@v4
70+
- name: Set up Go
71+
uses: actions/setup-go@v5
72+
with:
73+
go-version: '1.21.6'
74+
75+
- name: Build apiserver packages
76+
id: build
77+
shell: bash
78+
run: |
79+
make -j dist/packages
80+
81+
- name: Upload apiserver tar.gz packages
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: apiserver-packages-tar
85+
if-no-files-found: error
86+
path: |
87+
./api-server/dist/packages/*.tar.gz
88+
89+
upload-s3-packages:
90+
needs: ["build-packages"]
91+
permissions:
92+
id-token: write
93+
contents: read
94+
runs-on: ubuntu-latest
95+
environment: registry-creds
96+
# if: github.ref == 'refs/heads/main'
97+
98+
steps:
99+
- name: download tar.gz binary artifacts
100+
uses: actions/download-artifact@v4
101+
with:
102+
name: apiserver-packages-tar
103+
path: ./dist/packages
104+
105+
- name: Display structure of downloaded files
106+
run: ls -lah -R
107+
working-directory: ./dist/packages
108+
109+
- name: configure aws credentials
110+
uses: aws-actions/configure-aws-credentials@v4
111+
with:
112+
role-to-assume: ${{ secrets.AWS_ROLE }}
113+
role-session-name: apiserver-ci-deploy
114+
aws-region: us-east-1
115+
- name: copy binaries to s3
116+
run: |
117+
aws s3 sync dist/packages s3://instructlab-io/apiserver
118+
119+
build-workflow-complete:
120+
needs: ["build-packages", "upload-s3-packages"]
121+
runs-on: ubuntu-latest
122+
steps:
123+
- name: Build Complete
124+
run: echo "Build Complete"

api-server/Makefile

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
.PHONY: help
2+
help:
3+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-18s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
4+
5+
#
6+
# If you want to see the full commands, run:
7+
# NOISY_BUILD=y make
8+
#
9+
ifeq ($(NOISY_BUILD),)
10+
ECHO_PREFIX=@
11+
CMD_PREFIX=@
12+
else
13+
ECHO_PREFIX=@\#
14+
CMD_PREFIX=
15+
endif
16+
17+
# Pinned container image tags. Check for updates periodically.
18+
19+
APISERVER_VERSION?=$(shell date +%Y.%m.%d)
20+
APISERVER_RELEASE?=$(shell git describe --always --abbrev=6 --exclude qa --exclude prod)
21+
APISERVER_GCFLAGS?=
22+
23+
APISERVER_BUILD_PROFILE?=dev
24+
APISERVER_LDFLAGS:=$(APISERVER_LDFLAGS) -X main.Version=$(APISERVER_VERSION)-$(APISERVER_RELEASE)
25+
26+
CGO_ENABLED?=0
27+
ifeq ($(APISERVER_RACE_DETECTOR),1)
28+
CGO_ENABLED=1
29+
APISERVER_BUILD_FLAGS+=-race
30+
endif
31+
ifneq ($(APISERVER_BUILD_TAGS),)
32+
APISERVER_BUILD_FLAGS+=-tags $(APISERVER_BUILD_TAGS)
33+
endif
34+
ifeq ($(CGO_ENABLED),0)
35+
APISERVER_LDFLAGS+=-extldflags=-static
36+
endif
37+
38+
39+
# Crunchy DB operator does not work well on arm64, use an different overlay to work around it.
40+
UNAME_M := $(shell uname -m)
41+
ifeq ($(UNAME_M),arm64)
42+
OVERLAY?=arm64
43+
else
44+
OVERLAY?=dev
45+
endif
46+
47+
##@ Binaries
48+
49+
.PHONY: apiserver
50+
apiserver: dist/apiserver dist/apiserver-linux-arm64 dist/apiserver-linux-amd64 dist/apiserver-darwin-amd64 dist/apiserver-darwin-arm64 ## Build Instructlab UI API server
51+
52+
# Use go list to find all the go files that make up a binary.
53+
APISERVER_DEPS:= $(shell go list -deps -f '{{if (and .Module (eq .Module.Path "github.com/instructlab/ui/api-server"))}}{{$$dir := .Dir}}{{range .GoFiles}}{{$$dir}}/{{.}} {{end}}{{end}}' ./)
54+
55+
TAG=$(shell git rev-parse HEAD)
56+
57+
dist:
58+
$(CMD_PREFIX) mkdir -p $@
59+
60+
dist/apiserver: $(APISERVER_DEPS) | dist
61+
$(ECHO_PREFIX) printf " %-12s $@\n" "[GO BUILD]"
62+
$(CMD_PREFIX) CGO_ENABLED=$(CGO_ENABLED) go build $(APISERVER_BUILD_FLAGS) \
63+
-gcflags="$(APISERVER_GCFLAGS)" -ldflags="$(APISERVER_LDFLAGS)" -o $@ ./
64+
65+
dist/apiserver-%: $(APISERVER_DEPS) | dist
66+
$(ECHO_PREFIX) printf " %-12s $@\n" "[GO BUILD]"
67+
$(CMD_PREFIX) CGO_ENABLED=$(CGO_ENABLED) GOOS=$(word 2,$(subst -, ,$(basename $@))) GOARCH=$(word 3,$(subst -, ,$(basename $@))) \
68+
go build $(APISERVER_BUILD_FLAGS) -gcflags="$(APISERVER_GCFLAGS)" \
69+
-ldflags="$(APISERVER_LDFLAGS)" -o $@ ./
70+
dist/packages: \
71+
dist/packages/apiserver-linux-amd64.tar.gz \
72+
dist/packages/apiserver-linux-arm64.tar.gz \
73+
dist/packages/apiserver-darwin-amd64.tar.gz \
74+
dist/packages/apiserver-darwin-arm64.tar.gz \
75+
76+
dist/packages/%: apiserver
77+
$(CMD_PREFIX) mkdir -p $(basename $(basename $@))
78+
$(CMD_PREFIX) cp README.md $(basename $(basename $@))
79+
$(CMD_PREFIX) cp dist/apiserver-$(subst apiserver-,,$(basename $(basename $(@F))))$(if $(findstring windows,$@),.exe) $(basename $(basename $@))/ilab-apiserver$(if $(findstring windows,$@),.exe)
80+
$(CMD_PREFIX) if test "$(word 2,$(subst -, ,$(shell basename $@)))" = "windows" ; then \
81+
printf " %-12s dist/packages/$(@F)\n" "[ZIP]" ;\
82+
cd dist/packages && zip -q9r $(@F) $(basename $(basename $(@F))) ;\
83+
else \
84+
printf " %-12s dist/packages/$(@F)\n" "[TAR]" ;\
85+
cd dist/packages && tar -czf $(@F) $(basename $(basename $(@F))) ;\
86+
fi
87+
88+
.PHONY: clean
89+
clean: ## clean built binaries
90+
$(CMD_PREFIX) rm -rf dist

api-server/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ func main() {
181181
}
182182
return nil
183183
}
184-
185184
if err := rootCmd.Execute(); err != nil {
186185
fmt.Printf("Error executing command: %v\n", err)
187186
os.Exit(1)

0 commit comments

Comments
 (0)