Skip to content

Commit 500204e

Browse files
committed
feat: docs for running gsw with docker
feat: add github workflow for building the container fix: remove debug due to complexity fix: set `GSW_LOGGER_OUTPUT_PATHS` in the dockerfile
1 parent 64e9d78 commit 500204e

4 files changed

Lines changed: 87 additions & 20 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Build and publish Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
build-and-push-image:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
attestations: write
19+
id-token: write
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v5
23+
- name: Log in to the Container registry
24+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1
25+
with:
26+
registry: ${{ env.REGISTRY }}
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Extract metadata (tags, labels) for Docker
30+
id: meta
31+
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f
32+
with:
33+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34+
- name: Build and push Docker image
35+
id: push
36+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
37+
with:
38+
context: .
39+
file: cmd/Containerfile
40+
push: true
41+
tags: ${{ steps.meta.outputs.tags }}
42+
labels: ${{ steps.meta.outputs.labels }}
43+
44+
- name: Generate artifact attestation
45+
uses: actions/attest-build-provenance@v3
46+
with:
47+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
48+
subject-digest: ${{ steps.push.outputs.digest }}
49+
push-to-registry: true

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,39 @@ You can always run the GSW service by doing a `./gsw_service` after building. Fo
1212
### Compatibility
1313
Some machines do not have a /dev/shm directory. The directory used for shared memory can be changed with the flag `-shm (DIRECTORY_NAME)`. For example, `go run cmd/mem_view/mem_view.go -shm /someDirectory/RAMDrive`.
1414

15+
## Docker
16+
It may be easier to run the GSW in a docker container. This might be better for compatibility and easier for people on Windows hosts (as docker desktop will natively use a WLS 2 backend).
17+
18+
A dockerfile for GSW is provided in `./cmd/Containerfile` and can be built and run with:
19+
```shell
20+
$ docker build -t launch-gsw -f ./cmd/Containerfile .
21+
```
22+
23+
And the container could be started with:
24+
```shell
25+
$ docker run --name gsw-service \
26+
-p 11020:11020/udp \
27+
-p 13020:13020/udp \
28+
-p 12005:12005/udp \
29+
-p 12006:12006/udp \
30+
-p 12002:12002/udp \
31+
launch-gsw
32+
```
33+
34+
For simplicity, a `docker-compose` file is provided for building and running GSW, Grafana, and InfluxDB:
35+
```shell
36+
$ docker compose up --build
37+
```
38+
39+
### Attaching to the container
40+
41+
If you need to run any of the apps in `cmd/`, you can get a shell into the container using:
42+
```shell
43+
$ docker exec -it gsw-service sh
44+
```
45+
46+
All binaries are in PATH as the names of their folders in `cmd/`.
47+
1548
## Unit Tests
1649
There are several unit tests that can be run. You can do a `go test ./...` from the root project directory to execute all tests. It is also recommended to run with the -cover
1750
flag to get coverage statements.

cmd/Containerfile

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ FROM golang:1.25-alpine AS build
22

33
RUN apk add --update --no-cache build-base
44

5-
# TODO: document how to use delve
6-
RUN --mount=type=cache,target=/root/.cache/go-build \
7-
CGO_ENABLED=0 go install -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@latest
8-
95
WORKDIR /go/src/app
106

117
COPY go.mod .
@@ -16,28 +12,21 @@ RUN --mount=type=cache,id=gsw_mod,target=/go/pkg/mod \
1612

1713
COPY . .
1814

19-
ARG DEBUG=
20-
ENV USE_DELVE_DEBUG_FLAGS=${DEBUG}
21-
2215
RUN --mount=type=cache,id=gsw_mod,target=/go/pkg/mod \
2316
--mount=type=cache,id=gsw_build,target=/root/.cache/go-build \
2417
CGO_ENABLED=1 GOOS=linux go build \
2518
-trimpath \
26-
-o out/gsw_service \
19+
-o /build-output/bin/gsw_service \
2720
-v \
28-
# delve
29-
${USE_DELVE_DEBUG_FLAGS:+-gcflags "all=-N -l"} \
3021
./cmd/gsw_service.go
3122

3223
RUN --mount=type=cache,id=gsw_mod,target=/go/pkg/mod \
3324
--mount=type=cache,id=gsw_build,target=/root/.cache/go-build \
3425
for binary in grafana_live live_setup mem_view pipeline_benchmark telem_view udp_command; do \
3526
CGO_ENABLED=1 GOOS=linux go build \
3627
-trimpath \
37-
-o out/$binary \
28+
-o /build-output/bin/$binary \
3829
-v \
39-
# delve
40-
${USE_DELVE_DEBUG_FLAGS:+-gcflags "all=-N -l"} \
4130
./cmd/$binary/; \
4231
done
4332

@@ -46,13 +35,12 @@ FROM alpine
4635
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
4736

4837
COPY data /opt/app/data
49-
RUN mkdir -p /opt/app/data/logs && chown -R appuser:appgroup /opt/app/data/logs
50-
51-
COPY --from=build /go/bin/dlv /usr/bin/dlv
52-
COPY --from=build /go/src/app/out/ /usr/bin/
38+
COPY --from=build /build-output/bin/ /usr/bin/
5339

5440
WORKDIR /opt/app
5541

5642
USER appuser
5743

44+
ENV GSW_LOGGER_OUTPUT_PATHS=stdout
45+
5846
ENTRYPOINT [ "gsw_service" ]

compose.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ services:
33
build:
44
context: .
55
dockerfile: cmd/Containerfile
6-
args:
7-
DEBUG: ""
86
depends_on:
97
influxdb:
108
condition: service_started
119
grafana:
1210
condition: service_started
1311
environment:
1412
- GSW_DATABASE_HOST_NAME=influxdb
15-
- GSW_LOGGER_OUTPUT_PATHS=stdout
1613
ports:
1714
- 11020:11020/udp
1815
- 13020:13020/udp

0 commit comments

Comments
 (0)