Skip to content

Commit 27b0a2d

Browse files
committed
embed version and commit at build time
1 parent 17d29fc commit 27b0a2d

File tree

7 files changed

+54
-28
lines changed

7 files changed

+54
-28
lines changed

.devcontainer/devcontainer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@
77
"ghcr.io/devcontainers/features/github-cli:1": {},
88
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {}
99
},
10-
"customizations": {}
10+
"customizations": {
11+
"vscode": {
12+
"extensions": [
13+
"github.vscode-github-actions",
14+
]
15+
}
16+
}
1117
}

.github/workflows/deploy-to-cluster.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
name: Build and deploy jarvis to AKS
2929

30-
on:
30+
# on:
3131
# push:
3232
# branches:
3333
# - main
34-
workflow_dispatch:
34+
# workflow_dispatch:
3535

3636
env:
3737
AZURE_CONTAINER_REGISTRY: ${{ secrets.AZURE_CONTAINER_REGISTRY }}

.github/workflows/push-artifacts.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
goos: ${{ matrix.goos }}
3838
goarch: ${{ matrix.goarch }}
3939
goversion: "1.18"
40+
ldflags: "-X 'main.commit=${{ github.sha }}' -X 'main.version=${{ needs.create-release.outputs.tag_name }}'"
4041
md5sum: FALSE
4142
sha256sum: TRUE
4243
project_path: "./server"
@@ -46,13 +47,14 @@ jobs:
4647

4748
push-docker-image:
4849
runs-on: ubuntu-latest
50+
needs: [create-release]
4951
permissions:
5052
packages: write
5153
contents: read
5254
steps:
5355
- uses: actions/checkout@v3
5456
- name: Build the Docker image
55-
run: docker build -f ./Dockerfile ./server --tag jarvis:latest
57+
run: docker build -f ./Dockerfile ./server --tag jarvis:latest --build-arg JARVIS_BUILD_COMMIT=${{ github.sha }} --build-arg JARVIS_BUILD_VERSION=${{ needs.create-release.outputs.tag_name }}
5658
- name: Log in to registry
5759
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u USERNAME --password-stdin
5860
- name: Push image

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
12
FROM golang:1.18
23

4+
ARG JARVIS_BUILD_COMMIT="0000"
5+
ARG JARVIS_BUILD_VERSION="dev"
6+
37
WORKDIR /usr/src/app
48

59
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
610
COPY go.mod go.sum ./
711
RUN go mod download && go mod verify
812

913
COPY . .
10-
RUN go build -v -o /usr/local/bin/app ./...
14+
RUN go build \
15+
--ldflags "-X 'main.commit=$JARVIS_BUILD_COMMIT' -X 'main.version=$JARVIS_BUILD_VERSION'" \
16+
-v -o /usr/local/bin/app ./...
1117

1218
CMD ["app"]

rollout.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spec:
1616
"kubernetes.io/os": linux
1717
containers:
1818
- name: jarvis
19-
image: jarvisdevacr.azurecr.io/jarvis:1.0.0
19+
image: ghcr.io/joshspicer/jarvis:latest
2020
resources:
2121
requests:
2222
cpu: 100m

server/clusterRouter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ func ClusterRouter(bot *tgbotapi.BotAPI) *gin.Engine {
2626
}
2727

2828
func health(c *gin.Context) {
29-
c.String(http.StatusOK, "healthy")
29+
// Set no cache headers
30+
c.Header("Cache-Control", "no-cache, no-store, no-transform, must-revalidate, private, max-age=0")
31+
c.Header("Pragma", "no-cache")
32+
c.Header("Expires", "0")
33+
c.Header("X-Accel-Expires", "0")
34+
c.String(http.StatusOK, fmt.Sprintf("healthy\n%s\n%s", version, commit))
3035
}
3136

3237
func trustedKnock(c *gin.Context) {

server/main.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ import (
1010
"github.com/joho/godotenv"
1111
)
1212

13+
var (
14+
version = "dev"
15+
commit = "0000"
16+
)
17+
1318
func main() {
19+
fmt.Printf("[jarvis] %s, %s\n", version, commit)
20+
1421
// Get first argument to determine mode
1522
mode := determineMode()
1623

@@ -29,13 +36,13 @@ func main() {
2936
log.Printf("Starting cluster")
3037
bot := SetupTelegram()
3138
initializeCluster(bot, mode)
32-
case "router":
33-
log.Printf("Starting router")
34-
bot := SetupTelegram()
35-
initializeRouter(bot, mode)
36-
case "node":
37-
log.Printf("Starting node")
38-
initializeNode(mode)
39+
// case "home":
40+
// log.Printf("Starting home")
41+
// bot := SetupTelegram()
42+
// initializeHome(bot, mode)
43+
// case "node":
44+
// log.Printf("Starting node")
45+
// initializeNode(mode)
3946
default:
4047
log.Fatalf("Invalid mode: %s", mode)
4148
}
@@ -54,23 +61,23 @@ func initializeCluster(bot *tgbotapi.BotAPI, mode string) {
5461
router.Run(fmt.Sprintf(":%s", PORT))
5562
}
5663

57-
func initializeRouter(bot *tgbotapi.BotAPI, mode string) {
58-
botExtended := &BotExtended{bot}
59-
botExtended.SendMessageToPrimaryTelegramGroup("[narnia initializing]")
60-
SetupTelegramCommandHandler(botExtended, mode)
61-
}
64+
// func initializeHome(bot *tgbotapi.BotAPI, mode string) {
65+
// botExtended := &BotExtended{bot}
66+
// botExtended.SendMessageToPrimaryTelegramGroup("[narnia initializing]")
67+
// SetupTelegramCommandHandler(botExtended, mode)
68+
// }
6269

63-
func initializeNode(mode string) {
64-
router := NodeRouter()
70+
// func initializeNode(mode string) {
71+
// router := NodeRouter()
6572

66-
PORT := os.Getenv("PORT")
67-
if PORT == "" {
68-
PORT = "4000"
69-
}
70-
log.Printf("Serving at http://localhost:%s", PORT)
71-
router.Run(fmt.Sprintf(":%s", PORT))
73+
// PORT := os.Getenv("PORT")
74+
// if PORT == "" {
75+
// PORT = "4000"
76+
// }
77+
// log.Printf("Serving at http://localhost:%s", PORT)
78+
// router.Run(fmt.Sprintf(":%s", PORT))
7279

73-
}
80+
// }
7481

7582
func determineMode() string {
7683
DEFAULT_MODE := "cluster"

0 commit comments

Comments
 (0)