Skip to content

Commit 61a0486

Browse files
Feature/68 add release ci build job (#70)
* Added release steps for CI * Added release ci file * Fix naming of safe dir * Update sbom generation * Added install-tools target for makefile * Added install commands * Install dependencies script * Added install script * Install latest fixed by PR #72 * Fixed build instructions and script * Install cyclonedx for sbom * Fix path for sbom * Install cyclonedx in pipeline * Also install node for sbom * Set workdir of main to server
1 parent 53e55da commit 61a0486

File tree

5 files changed

+224
-5
lines changed

5 files changed

+224
-5
lines changed

.github/workflows/release.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+\-?*'
7+
8+
jobs:
9+
compile:
10+
name: Build binary
11+
runs-on: ubuntu-latest
12+
container:
13+
image: golangci/golangci-lint:latest
14+
steps:
15+
- name: Checkout Code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
- name: Make repo safe
20+
run: git config --global --add safe.directory /__w/SOARCA-GUI/SOARCA-GUI
21+
- name: Install Templ
22+
run: go install github.com/a-h/templ/cmd/templ@latest
23+
24+
- name: Setup node
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 18
28+
- run: npm ci
29+
30+
- name: Build with make
31+
run: make compile
32+
33+
- name: 'Upload Artifact'
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: ${{ github.sha }}
37+
path: bin/*
38+
retention-days: 1
39+
40+
41+
docker-build:
42+
needs: compile
43+
name: Build docker image and push it to docker hub
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Checkout Code
47+
uses: actions/checkout@v4
48+
with:
49+
fetch-depth: 0
50+
- name: Make repo safe
51+
run: git config --global --add safe.directory /__w/SOARCA-GUI/SOARCA-GUI
52+
53+
- name: Set up QEMU
54+
uses: docker/setup-qemu-action@v3
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v3
57+
58+
- name: Download bin
59+
uses: actions/download-artifact@v4
60+
with:
61+
pattern: ${{ github.sha }}
62+
63+
- name: Move files to bin folder and make executable
64+
run: |
65+
mkdir -p bin
66+
mv ${{ github.sha }}/* ./bin/
67+
chmod +x bin/soarca-gui-*
68+
69+
- name: Login to Docker Hub
70+
uses: docker/login-action@v3
71+
with:
72+
username: ${{ secrets.DOCKER_HUB_USER }}
73+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
74+
75+
- name: Get version
76+
run: |
77+
export VERSION=$(git describe --tags --dirty)
78+
echo "describe_version=$(git describe --tags --dirty)" >> "$GITHUB_ENV"
79+
80+
- name: Build and push
81+
uses: docker/build-push-action@v5
82+
with:
83+
context: .
84+
build-args: |
85+
VERSION=${{ env.describe_version }}
86+
push: true
87+
tags: cossas/soarca-gui:${{ env.describe_version }},cossas/soarca-gui:latest
88+
89+
90+
release-binary:
91+
needs: compile
92+
name: Create release artifacts
93+
runs-on: ubuntu-latest
94+
steps:
95+
- name: Setup Go
96+
uses: actions/setup-go@v4
97+
with:
98+
go-version: '1.23.x'
99+
- name: Import GPG key
100+
uses: crazy-max/ghaction-import-gpg@v6
101+
with:
102+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
103+
passphrase: ${{ secrets.GPG_PASSPHRASE }}
104+
- name: Checkout Code
105+
uses: actions/checkout@v4
106+
with:
107+
fetch-depth: 0
108+
- name: Make repo safe
109+
run: git config --global --add safe.directory /__w/SOARCA-GUI/SOARCA-GUI
110+
111+
- name: Setup node
112+
uses: actions/setup-node@v4
113+
with:
114+
node-version: 18
115+
- run: npm ci
116+
117+
- name: Build and sbom
118+
run: |
119+
go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest
120+
go install github.com/a-h/templ/cmd/templ@latest
121+
make sbom
122+
zip -r bin/sbom.zip bin
123+
124+
- name: Release soarca gui binary
125+
uses: goreleaser/goreleaser-action@v5
126+
with:
127+
distribution: goreleaser
128+
version: latest
129+
args: release --clean
130+
workdir: server
131+
env:
132+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133+
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
134+
135+
- name: Upload release sbom
136+
uses: actions/github-script@v4
137+
with:
138+
script: |
139+
const fs = require('fs');
140+
const tag = context.ref.replace("refs/tags/", "");
141+
// Get release for this tag
142+
const release = await github.repos.getReleaseByTag({
143+
owner: context.repo.owner,
144+
repo: context.repo.repo,
145+
tag
146+
});
147+
// Upload the release asset
148+
await github.repos.uploadReleaseAsset({
149+
owner: context.repo.owner,
150+
repo: context.repo.repo,
151+
release_id: release.data.id,
152+
name: "sbom.zip",
153+
data: await fs.readFileSync("bin/sbom.zip")
154+
});

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ plugins/*
88
.vscode/*
99
build/*
1010
!build/build.md
11+
!build/dependencies.sh
1112
bin/*
1213
swaggerdocs/*
1314
**.env

Makefile

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: dev-server dev-tailwind dev-templ dev build-server build-tailwind build-templ build launch deploy clean test
1+
.PHONY: install-tools dev-server dev-tailwind dev-templ dev build-server build-tailwind build-templ build launch deploy clean test
22

33

44
BINARY_NAME = soarca-gui
@@ -10,6 +10,14 @@ GOLDFLAGS += -X main.Version=$(VERSION)
1010
GOLDFLAGS += -X main.Buildtime=$(BUILDTIME)
1111
GOFLAGS = -ldflags "$(GOLDFLAGS)"
1212

13+
#-----------------------------------------------------
14+
# install
15+
#-----------------------------------------------------
16+
17+
install-tools:
18+
bash build/dependencies.sh
19+
20+
1321
#-----------------------------------------------------
1422
# DEV
1523
#-----------------------------------------------------
@@ -57,9 +65,8 @@ build: build-templ build-tailwind build-server
5765

5866
build-server:
5967
echo "Compiling for every OS and Platform"
60-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-linux-amd64 $(GOFLAGS) ./server/main.go
61-
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/${BINARY_NAME}-${VERSION}-darwin-arm64 $(GOFLAGS) ./server/main.go
62-
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-windows-amd64 $(GOFLAGS) ./server/main.go
68+
CGO_ENABLED=0 go build -o build/${BINARY_NAME} $(GOFLAGS) ./server/main.go
69+
6370

6471

6572
docker:
@@ -85,4 +92,17 @@ run: docker
8592
test: build-templ
8693
go test ./... -v
8794

88-
.DEFAULT_GOAL := dev
95+
.DEFAULT_GOAL := build
96+
97+
98+
# release
99+
100+
compile: build-templ build-tailwind
101+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-linux-amd64 $(GOFLAGS) server/main.go
102+
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/${BINARY_NAME}-${VERSION}-darwin-arm64 $(GOFLAGS) server/main.go
103+
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-windows-amd64 $(GOFLAGS) server/main.go
104+
105+
sbom: build-templ compile
106+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 cyclonedx-gomod app -main server -json -licenses -output bin/${BINARY_NAME}-${VERSION}-linux-amd64.bom.json
107+
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 cyclonedx-gomod app -main server -json -licenses -output bin/${BINARY_NAME}-${VERSION}-darwin-amd64.bom.json
108+
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 cyclonedx-gomod app -main server -json -licenses -output bin/${BINARY_NAME}-${VERSION}-windows-amd64.bom.json

build/build.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Building the SOARCA-GUI
2+
3+
4+
Install dependencies (Linux):
5+
6+
```
7+
make install-tools
8+
9+
# Export paths to ~/.bashrc
10+
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
11+
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
12+
echo 'export PATH=$PATH:$GOROOT/bin' >> ~/.bashrc
13+
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
14+
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
15+
16+
# Reconnect of start a new shell or
17+
source ~/.bashrc
18+
19+
20+
```
21+

build/dependencies.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/bash
2+
set -euxo pipefail
3+
4+
# Install go
5+
wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gz
6+
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gz
7+
8+
export PATH=$PATH:/usr/local/go/bin
9+
export GOROOT=/usr/local/go
10+
export PATH=$PATH:$GOROOT/bin
11+
export GOPATH=$HOME/go
12+
export PATH=$PATH:$GOPATH/bin
13+
14+
# Install nvm
15+
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
16+
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
17+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
18+
nvm install 18
19+
20+
# Install dependencies for project
21+
go install github.com/a-h/templ/cmd/templ@latest
22+
go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest
23+
npm install

0 commit comments

Comments
 (0)