Skip to content

Commit f9725e1

Browse files
committed
touched up code, added GH workflow
1 parent 4c2153b commit f9725e1

File tree

9 files changed

+170
-69
lines changed

9 files changed

+170
-69
lines changed

.env.example

-4
This file was deleted.

.github/workflows/release.yaml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build and publish docker image
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
7+
jobs:
8+
push_to_registry:
9+
name: Push Docker image to Quay
10+
runs-on: ubuntu-latest
11+
permissions:
12+
packages: write
13+
contents: read
14+
attestations: write
15+
id-token: write
16+
steps:
17+
- name: Check out the repo
18+
uses: actions/checkout@v4
19+
20+
- name: Log in to Quay
21+
uses: docker/login-action@v3
22+
with:
23+
registry: quay.io
24+
username: ${{ secrets.QUAY_USERNAME }}
25+
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
26+
27+
- name: Extract metadata (tags, labels) for Docker
28+
id: meta
29+
uses: docker/metadata-action@v5
30+
with:
31+
images: quay.io/road/heartbeat-collector
32+
tags: |
33+
type=raw,value=latest,enable=true
34+
type=sha,prefix=,format=long
35+
36+
- name: Build and push Docker image
37+
id: push
38+
uses: docker/build-push-action@v6
39+
with:
40+
context: .
41+
file: ./Dockerfile
42+
push: true
43+
tags: ${{ steps.meta.outputs.tags }}
44+
labels: ${{ steps.meta.outputs.labels }}
45+
46+
- name: Generate artifact attestation
47+
uses: actions/attest-build-provenance@v1
48+
with:
49+
subject-name: quay.io/road/heartbeat-collector
50+
subject-digest: ${{ steps.push.outputs.digest }}
51+
push-to-registry: true

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ go.work.sum
2323

2424
# env file
2525
.env
26-
heartbeats.db
26+
heartbeats.db
27+
.idea

Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23-alpine AS build-stage
1+
FROM golang:1.24-alpine AS build-stage
22

33
WORKDIR /app
44

@@ -21,7 +21,6 @@ RUN apk --no-cache add sqlite ca-certificates
2121
WORKDIR /app
2222

2323
COPY --from=build-stage /app/heartbeat-collector .
24-
COPY --from=build-stage /app/heartbeats.db /app/heartbeats.db
2524

2625
EXPOSE 8080 8081
2726

README.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,28 @@
66
To run the heartbeat collector, use the following command in the root of the project
77

88
```sh
9-
task watch
9+
task run
1010
```
1111

1212
### Creating a heartbeat
1313

1414
```sh
15-
curl -X PUT http://localhost:8080/hb/secret -d '{
16-
"secret": "secret",
15+
curl -X PUT http://localhost:8181/hb/{id} -d '{
1716
"expiry": "2025-12-31T23:59:59Z",
1817
"label": "example",
1918
"metadata": {
2019
"k1": "v1",
2120
"k2": "v2"
2221
}
2322
}' -H "Content-Type: application/json"
24-
25-
Heartbeat registered
2623
```
2724

2825
### Reading a heartbeat
2926
```sh
30-
curl -X GET http://localhost:8081/hb/secret
27+
curl -X GET http://localhost:8080/hb/{id}
3128

3229
{
33-
"secret":"secret",
30+
"id":"id",
3431
"expiry":"2025-12-31T23:59:59Z",
3532
"label":"example-label",
3633
"metadata":

Taskfile.yml

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ tasks:
6161
-v {{.SQLITE_DSN}}:/app/{{.SQLITE_DSN}} \
6262
heartbeat-collector:latest
6363
64+
run:
65+
desc: "Run the application"
66+
cmds:
67+
- cmd: go run main.go
68+
6469
watch:
6570
desc: "Run the application with live reloading"
6671
cmds:

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
module github.com/e-flux-platform/heartbeat-collector
22

3-
go 1.23
3+
go 1.24.1
44

55
require (
66
github.com/mattn/go-sqlite3 v1.14.24
77
github.com/urfave/cli/v2 v2.27.6
8+
golang.org/x/sync v0.12.0
89
)
910

1011
require (

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ github.com/urfave/cli/v2 v2.27.6 h1:VdRdS98FNhKZ8/Az8B7MTyGQmpIr36O1EHybx/LaZ4g=
88
github.com/urfave/cli/v2 v2.27.6/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
99
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
1010
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
11+
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
12+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=

0 commit comments

Comments
 (0)