-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00b510e
commit fdff491
Showing
10 changed files
with
279 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ project_name: serviceradar | |
before: | ||
hooks: | ||
- go mod tidy | ||
- ./scripts/build-web.sh | ||
|
||
builds: | ||
- id: agent | ||
|
@@ -41,22 +42,19 @@ builds: | |
ldflags: | ||
- -s -w -X main.version={{.Version}} | ||
|
||
dockers: | ||
- id: cloud | ||
goos: linux | ||
goarch: amd64 | ||
image_templates: | ||
- "ghcr.io/mfreeman451/serviceradar-cloud:{{ .Version }}" | ||
- "ghcr.io/mfreeman451/serviceradar-cloud:latest" | ||
dockerfile: Dockerfile.build | ||
build_flag_templates: | ||
- "--platform=linux/amd64" | ||
extra_files: | ||
- web | ||
- cmd/cloud | ||
- pkg/cloud | ||
- go.mod | ||
- go.sum | ||
- id: serviceradar-cloud | ||
main: ./cmd/cloud/main.go | ||
binary: serviceradar-cloud | ||
dir: . | ||
goos: | ||
- linux | ||
goarch: | ||
- amd64 | ||
ldflags: | ||
- -s -w -X main.version={{.Version}} | ||
hooks: | ||
pre: | ||
- ./scripts/build-cloud.sh {{ .Version }} | ||
|
||
nfpms: | ||
- id: agent | ||
|
@@ -107,6 +105,35 @@ nfpms: | |
postinstall: packaging/poller/scripts/postinstall.sh | ||
preremove: packaging/poller/scripts/preremove.sh | ||
|
||
- id: cloud | ||
package_name: serviceradar-cloud | ||
file_name_template: "{{ .PackageName }}_{{ .Version }}" | ||
builds: | ||
- serviceradar-cloud | ||
vendor: ServiceRadar | ||
homepage: https://github.com/mfreeman451/serviceradar | ||
maintainer: Michael Freeman <[email protected]> | ||
description: ServiceRadar Cloud Component | ||
license: MIT | ||
formats: | ||
- deb | ||
dependencies: | ||
- systemd | ||
contents: | ||
- src: dist/cloud_linux_amd64_v1/serviceradar-cloud | ||
dst: /usr/local/bin/serviceradar-cloud | ||
- src: packaging/cloud/systemd/serviceradar-cloud.service | ||
dst: /lib/systemd/system/serviceradar-cloud.service | ||
- src: packaging/cloud/config/cloud.json | ||
dst: /etc/serviceradar/cloud.json | ||
type: config | ||
- src: pkg/cloud/api/web/dist | ||
dst: /usr/local/share/serviceradar-cloud/web/dist | ||
type: "tree" | ||
scripts: | ||
postinstall: packaging/cloud/scripts/postinstall.sh | ||
preremove: packaging/cloud/scripts/preremove.sh | ||
|
||
- id: dusk-checker | ||
package_name: serviceradar-dusk-checker | ||
file_name_template: "{{ .PackageName }}_{{ .Version }}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Stage 1: Build the web UI | ||
FROM --platform=linux/amd64 node:18-bullseye AS web-builder | ||
|
||
WORKDIR /web-build | ||
|
||
COPY web/package*.json ./ | ||
RUN npm install | ||
COPY web/ . | ||
RUN npm run build | ||
|
||
# Stage 2: Build the Go binary | ||
FROM --platform=linux/amd64 golang:1.23-bullseye | ||
|
||
WORKDIR /src | ||
|
||
# Install build dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
gcc \ | ||
libc6-dev \ | ||
libsqlite3-dev | ||
|
||
# Copy go mod files first for better caching | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
# Copy the rest of the source | ||
COPY . . | ||
|
||
# Copy the built web UI from the previous stage | ||
COPY --from=web-builder /web-build/dist ./pkg/cloud/api/web/dist | ||
|
||
# Build the cloud service | ||
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \ | ||
go build -o serviceradar-cloud ./cmd/cloud |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
FROM --platform=linux/amd64 golang:1.23-bullseye | ||
|
||
# Install Node.js and npm | ||
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ | ||
&& apt-get update \ | ||
&& apt-get install -y \ | ||
gcc \ | ||
libc6-dev \ | ||
libsqlite3-dev \ | ||
make \ | ||
nodejs \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /src | ||
|
||
# Copy go mod files first for better caching | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
# Copy the rest of the source | ||
COPY . . | ||
|
||
# Build web interface | ||
RUN cd web && npm install && npm run build \ | ||
&& mkdir -p /src/pkg/cloud/api/web \ | ||
&& cp -r dist /src/pkg/cloud/api/web/ | ||
|
||
# Build the cloud service | ||
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \ | ||
go build -o serviceradar-cloud ./cmd/cloud |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
echo "Creating packaging structure..." | ||
|
||
# Create packaging structure | ||
mkdir -p packaging/{agent,poller,cloud,dusk}/{config,systemd,scripts} | ||
|
||
# Function to get component directory name | ||
get_component_dir() { | ||
case $1 in | ||
"dusk-checker") echo "dusk" ;; | ||
*) echo "$1" ;; | ||
esac | ||
} | ||
|
||
# Extract configuration files from setup scripts | ||
for script in setup-deb-*.sh; do | ||
component=$(echo $script | sed 's/setup-deb-\(.*\)\.sh/\1/') | ||
component_dir=$(get_component_dir "$component") | ||
echo "Processing $component (directory: $component_dir)..." | ||
|
||
# Copy setup script as reference | ||
cp "$script" "packaging/$component_dir/scripts/package.sh" | ||
|
||
# Extract config and systemd files based on component | ||
case $component in | ||
"agent") | ||
# Extract agent configuration | ||
awk '/cat > "\${PKG_ROOT}\/etc\/serviceradar\/agent.json"/,/^EOF/' "$script" | sed '1d;$d' > "packaging/agent/config/agent.json" | ||
|
||
# Extract systemd service | ||
awk '/cat > "\${PKG_ROOT}\/lib\/systemd\/system\/serviceradar-agent.service"/,/^EOF/' "$script" | sed '1d;$d' > "packaging/agent/systemd/serviceradar-agent.service" | ||
;; | ||
|
||
"poller") | ||
# Extract poller configuration | ||
awk '/cat > "\${PKG_ROOT}\/etc\/serviceradar\/poller.json"/,/^EOF/' "$script" | sed '1d;$d' > "packaging/poller/config/poller.json" | ||
|
||
# Extract systemd service | ||
awk '/cat > "\${PKG_ROOT}\/lib\/systemd\/system\/serviceradar-poller.service"/,/^EOF/' "$script" | sed '1d;$d' > "packaging/poller/systemd/serviceradar-poller.service" | ||
;; | ||
|
||
"cloud") | ||
# Extract cloud configuration | ||
awk '/cat > "\${PKG_ROOT}\/etc\/serviceradar\/cloud.json"/,/^EOF/' "$script" | sed '1d;$d' > "packaging/cloud/config/cloud.json" | ||
|
||
# Extract systemd service | ||
awk '/cat > "\${PKG_ROOT}\/lib\/systemd\/system\/serviceradar-cloud.service"/,/^EOF/' "$script" | sed '1d;$d' > "packaging/cloud/systemd/serviceradar-cloud.service" | ||
;; | ||
|
||
"dusk-checker") | ||
# Extract dusk configuration | ||
awk '/cat > "\${PKG_ROOT}\/etc\/serviceradar\/checkers\/dusk.json"/,/^EOF/' "$script" | sed '1d;$d' > "packaging/dusk/config/dusk.json" | ||
# Extract external configuration | ||
awk '/cat > "\${PKG_ROOT}\/etc\/serviceradar\/checkers\/external.json"/,/^EOF/' "$script" | sed '1d;$d' > "packaging/dusk/config/external.json" | ||
;; | ||
esac | ||
done | ||
|
||
# Create postinstall and preremove scripts for each component | ||
for component_dir in agent poller cloud dusk; do | ||
echo "Creating install scripts for $component_dir..." | ||
|
||
# Create postinstall script | ||
cat > "packaging/${component_dir}/scripts/postinstall.sh" << 'EOF' | ||
#!/bin/sh | ||
set -e | ||
# Create serviceradar user if it doesn't exist | ||
if ! id -u serviceradar >/dev/null 2>&1; then | ||
useradd --system --no-create-home --shell /usr/sbin/nologin serviceradar | ||
fi | ||
# Create required directories | ||
mkdir -p /etc/serviceradar | ||
mkdir -p /var/lib/serviceradar | ||
# Create checkers directory if this is the dusk component | ||
if [ "${component_dir}" = "dusk" ]; then | ||
mkdir -p /etc/serviceradar/checkers | ||
fi | ||
# Set permissions | ||
chown -R serviceradar:serviceradar /etc/serviceradar | ||
chmod -R 755 /etc/serviceradar | ||
# Only try to manage service if it exists | ||
if [ -f "/lib/systemd/system/serviceradar-${component_dir}.service" ]; then | ||
# Reload systemd | ||
systemctl daemon-reload | ||
# Enable and start service | ||
systemctl enable "serviceradar-${component_dir}" | ||
systemctl start "serviceradar-${component_dir}" | ||
fi | ||
# Set required capability for ICMP scanning if this is the agent | ||
if [ "${component_dir}" = "agent" ] && [ -x /usr/local/bin/serviceradar-agent ]; then | ||
setcap cap_net_raw=+ep /usr/local/bin/serviceradar-agent | ||
fi | ||
EOF | ||
|
||
# Create preremove script | ||
cat > "packaging/${component_dir}/scripts/preremove.sh" << 'EOF' | ||
#!/bin/sh | ||
set -e | ||
# Only try to manage service if it exists | ||
if [ -f "/lib/systemd/system/serviceradar-${component_dir}.service" ]; then | ||
# Stop and disable service | ||
systemctl stop "serviceradar-${component_dir}" | ||
systemctl disable "serviceradar-${component_dir}" | ||
fi | ||
EOF | ||
|
||
# Make scripts executable | ||
chmod +x "packaging/${component_dir}/scripts/"{postinstall,preremove}.sh | ||
done | ||
|
||
echo "Packaging structure created successfully!" | ||
echo "Directory structure:" | ||
find packaging -type f | sort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
VERSION=$1 | ||
if [ -z "$VERSION" ]; then | ||
VERSION="dev" | ||
fi | ||
|
||
echo "Building cloud component version ${VERSION}" | ||
|
||
# Ensure output directory exists | ||
mkdir -p dist/cloud_linux_amd64_v1 | ||
|
||
# Build using Docker | ||
docker build -f Dockerfile.cloud \ | ||
--build-arg VERSION="${VERSION}" \ | ||
-t serviceradar-cloud-build:${VERSION} . | ||
|
||
# Extract binary | ||
CONTAINER_ID=$(docker create serviceradar-cloud-build:${VERSION}) | ||
docker cp ${CONTAINER_ID}:/src/serviceradar-cloud dist/cloud_linux_amd64_v1/ | ||
docker rm ${CONTAINER_ID} | ||
|
||
echo "Cloud build complete" |
Oops, something went wrong.