Skip to content

Commit fa2fccc

Browse files
feat: add version and deb build
Co-authored-by: Alessio Perugini <alessio@perugini.xyz>
1 parent 23053dc commit fa2fccc

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

cmd/arduino-app-cli/daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func newDaemonCmd(docker *dockerClient.Client) *cobra.Command {
2929

3030
func httpHandler(ctx context.Context, dockerClient *dockerClient.Client, daemonPort string) {
3131
slog.Info("Starting HTTP server", slog.String("address", ":"+daemonPort))
32-
apiSrv := api.NewHTTPRouter(dockerClient)
32+
apiSrv := api.NewHTTPRouter(dockerClient, Version)
3333

3434
httpSrv := http.Server{
3535
Addr: ":" + daemonPort,

cmd/arduino-app-cli/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56
"log/slog"
67

78
dockerClient "github.com/docker/docker/client"
89
"github.com/spf13/cobra"
910
"go.bug.st/cleanup"
1011
)
1112

13+
// Version will be set a build time with -ldflags
14+
var Version string = "0.0.0-dev"
15+
1216
func main() {
1317
docker, err := dockerClient.NewClientWithOpts(
1418
dockerClient.FromEnv,
@@ -30,6 +34,13 @@ func main() {
3034
newAppCmd(docker),
3135
newCompletionCommand(),
3236
newDaemonCmd(docker),
37+
&cobra.Command{
38+
Use: "version",
39+
Short: "Print the version number of Arduino App CLI",
40+
Run: func(cmd *cobra.Command, args []string) {
41+
fmt.Println("Arduino App CLI v" + Version)
42+
},
43+
},
3344
)
3445

3546
ctx := context.Background()

debian/Dockerfile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@ FROM golang:1.24.2 AS go
22

33
ARG BINARY_NAME
44
RUN test -n "${BINARY_NAME}" || (echo "Error: BINARY_NAME is not set" && exit 1)
5+
ARG VERSION
6+
RUN test -n "${VERSION}" || (echo "Error: VERSION is not set" && exit 1)
7+
ARG ARCH
8+
RUN test -n "${ARCH}" || (echo "Error: ARCH is not set" && exit 1)
59

610
COPY . /app
711
WORKDIR /app
8-
RUN GOOS=linux go build -o ${BINARY_NAME} ./cmd/${BINARY_NAME}
12+
RUN GOOS=linux GOARCH=${ARCH} go build -ldflags "-X 'main.Version=${VERSION}'" -o ${BINARY_NAME} ./cmd/${BINARY_NAME}
913

1014
FROM debian:bookworm AS debian
1115

12-
ARG VERSION="1.0.0"
16+
ARG VERSION
17+
RUN test -n "${VERSION}" || (echo "Error: VERSION is not set" && exit 1)
1318
ARG REVISION="1"
19+
ARG ARCH
20+
RUN test -n "${ARCH}" || (echo "Error: ARCH is not set" && exit 1)
1421
ARG DEB_NAME
1522
RUN test -n "${DEB_NAME}" || (echo "Error: DEB_NAME is not set" && exit 1)
1623
ARG BINARY_NAME
@@ -21,9 +28,10 @@ RUN apt-get update && apt-get install -y sed
2128
COPY ./debian/${DEB_NAME} /${DEB_NAME}/
2229
COPY --from=go /app/${BINARY_NAME} /${DEB_NAME}/usr/bin/${BINARY_NAME}
2330

24-
RUN sed -i "s/ARCH/$(dpkg --print-architecture)/" /${DEB_NAME}/DEBIAN/control && \
31+
RUN sed -i "s/ARCH/${ARCH}/" /${DEB_NAME}/DEBIAN/control && \
32+
sed -i "s/VERSION/${VERSION}/" /${DEB_NAME}/DEBIAN/control && \
2533
dpkg-deb --build --root-owner-group /${DEB_NAME} &&\
26-
mv /${DEB_NAME}.deb "/${DEB_NAME}_${VERSION}-${REVISION}_$(dpkg --print-architecture).deb"
34+
mv /${DEB_NAME}.deb "/${DEB_NAME}_${VERSION}-${REVISION}_${ARCH}.deb"
2735

2836
FROM scratch
2937

debian/orchestrator/DEBIAN/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: arduino-orchestrator
2-
Version: 1.0
2+
Version: VERSION
33
Architecture: ARCH
44
Maintainer: arduino <support@arduino.cc>
55
Description: Arduino application orchestrator

internal/api/api.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ import (
66

77
"github.com/arduino/arduino-app-cli/internal/api/handlers"
88
"github.com/arduino/arduino-app-cli/internal/orchestrator"
9+
"github.com/arduino/arduino-app-cli/pkg/render"
910

1011
dockerClient "github.com/docker/docker/client"
1112
)
1213

13-
func NewHTTPRouter(dockerClient *dockerClient.Client) http.Handler {
14+
func NewHTTPRouter(dockerClient *dockerClient.Client, version string) http.Handler {
1415
mux := http.NewServeMux()
1516

17+
mux.HandleFunc("/v1/version", func(w http.ResponseWriter, r *http.Request) {
18+
render.EncodeResponse(w, http.StatusOK, struct {
19+
Version string `json:"version"`
20+
}{
21+
Version: version,
22+
})
23+
})
24+
1625
mux.Handle("GET /v1/apps", handlers.HandleAppList(dockerClient))
1726
mux.Handle("POST /v1/apps", handlers.HandleAppCreate(dockerClient))
1827

0 commit comments

Comments
 (0)