File tree Expand file tree Collapse file tree 5 files changed +35
-7
lines changed Expand file tree Collapse file tree 5 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ func newDaemonCmd(docker *dockerClient.Client) *cobra.Command {
2929
3030func 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 ,
Original file line number Diff line number Diff line change @@ -2,13 +2,17 @@ package main
22
33import (
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+
1216func 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 ()
Original file line number Diff line number Diff line change @@ -2,15 +2,22 @@ FROM golang:1.24.2 AS go
22
33ARG BINARY_NAME
44RUN 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
610COPY . /app
711WORKDIR /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
1014FROM 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)
1318ARG REVISION="1"
19+ ARG ARCH
20+ RUN test -n "${ARCH}" || (echo "Error: ARCH is not set" && exit 1)
1421ARG DEB_NAME
1522RUN test -n "${DEB_NAME}" || (echo "Error: DEB_NAME is not set" && exit 1)
1623ARG BINARY_NAME
@@ -21,9 +28,10 @@ RUN apt-get update && apt-get install -y sed
2128COPY ./debian/${DEB_NAME} /${DEB_NAME}/
2229COPY --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
2836FROM scratch
2937
Original file line number Diff line number Diff line change 11Package: arduino-orchestrator
2- Version: 1.0
2+ Version: VERSION
33Architecture: ARCH
44Maintainer: arduino <support@arduino.cc>
55Description: Arduino application orchestrator
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments