Golang based Solace client in Docker

subhoatg
subhoatg Member Posts: 17

Hi,

I am trying to create a docker image that would contain the golang based subscriber. The subscriber is based on https://github.com/SolaceSamples/solace-samples-go/blob/main/patterns/direct_subscriber.go

The DockerFile looks like the following.

FROM golang:1.18.0-alpine3.15 as builder


WORKDIR /app


#bring the go project dependencies
RUN apk add --update --no-cache ca-certificates git
RUN apk add build-base
# Copy the local package files to the container's workspace.
COPY patterns/direct_subscriber.go ./direct_subscriber.go
COPY go.mod go.sum ./
RUN go mod download


RUN ls /app
# RUN go build -o main .
#build the go project
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -o main .



#main image
# FROM scratch
FROM alpine:3.15.2


ENV APP_USER app
ENV APP_HOME /app
ENV GROUP_ID 3000
ENV USER_ID 1000


RUN addgroup -g ${GROUP_ID} -S ${APP_USER} && adduser -u ${USER_ID} -S ${APP_USER} -G ${APP_USER}
RUN mkdir -p $APP_HOME


WORKDIR $APP_HOME


# Copy the output from builder image to main image
COPY --from=builder /app ./


RUN chown -R $APP_USER:$APP_USER $APP_HOME


USER $APP_USER


# Run the sync agent executable by default when the container starts.
ENTRYPOINT ["./main"]


The docker build fails with the following error.


=> ERROR [builder 10/10] RUN CGO_ENABLED=0 GOOS=linux go build -o main .                                                                                                                                                                                                                                    0.4s
------
 > [builder 10/10] RUN CGO_ENABLED=0 GOOS=linux go build -o main .:
#19 0.251 # solace.dev/go/messaging/pkg/solace/subcode
#19 0.251 /go/pkg/mod/solace.dev/go/messaging@v1.0.1/pkg/solace/subcode/subcode.go:41:15: undefined: ccsmp.SolClientSubCodeToString
#19 0.251 /go/pkg/mod/solace.dev/go/messaging@v1.0.1/pkg/solace/subcode/subcode.go:41:46: undefined: ccsmp.SolClientSubCode
#19 0.289 # solace.dev/go/messaging/internal/impl/constants
#19 0.289 /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/impl/constants/default_properties.go:35:8: undefined: ccsmp.SolClientSessionPropTopicDispatch
#19 0.289 /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/impl/constants/default_properties.go:36:8: undefined: ccsmp.SolClientSessionPropSendBlocking
#19 0.289 /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/impl/constants/default_properties.go:37:8: undefined: ccsmp.SolClientSessionPropReapplySubscriptions
#19 0.289 /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/impl/constants/default_properties.go:38:8: undefined: ccsmp.SolClientSessionPropIgnoreDupSubscriptionError
#19 0.289 /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/impl/constants/default_properties.go:39:8: undefined: ccsmp.SolClientSessionPropReconnectRetries
#19 0.289 /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/impl/constants/default_properties.go:40:8: undefined: ccsmp.SolClientSessionPropGuaranteedWithWebTransport
#19 0.289 /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/impl/constants/default_properties.go:41:8: undefined: ccsmp.SolClientSessionPropPubWindowSize
------
executor failed running [/bin/sh -c CGO_ENABLED=0 GOOS=linux go build -o main .]: exit code: 2


Could you please help in what could be missing ?

Tagged:

Best Answer

  • amackenzie
    amackenzie Member, Employee Posts: 260 Solace Employee
    #2 Answer ✓

    Hi @subhoatg

    Unfortunately, we don’t currently support Alpine, but support will be coming soon in the next version of the Go API! You’ll have to switch to another base image for now such as golang:buster and ubuntu:latest for your build and main images respectively.

    In addition, the Solace PubSub+ Go API uses C code under the hood for performance, thus requires CGO_ENABLED=1 when building.

Answers

  • amackenzie
    amackenzie Member, Employee Posts: 260 Solace Employee
    #3 Answer ✓

    Hi @subhoatg

    Unfortunately, we don’t currently support Alpine, but support will be coming soon in the next version of the Go API! You’ll have to switch to another base image for now such as golang:buster and ubuntu:latest for your build and main images respectively.

    In addition, the Solace PubSub+ Go API uses C code under the hood for performance, thus requires CGO_ENABLED=1 when building.

  • subhoatg
    subhoatg Member Posts: 17

    @amackenzie Thanks for your reply.

    I tried with the below Dockerfile.

    FROM golang:1.18-buster as builder
    
    
    WORKDIR /app
    
    
    RUN apt update
    RUN apt install build-essential -y
    COPY patterns/direct_subscriber.go ./direct_subscriber.go
    COPY go.mod go.sum ./
    RUN go mod download
    
    
    RUN ls /app
    WORKDIR /app
    RUN CGO_ENABLED=1 GOOS=linux go build -o main .
    
    
    
    #main image
    FROM ubuntu:latest
    
    
    ENV APP_USER app
    ENV APP_HOME /app
    
    
    RUN mkdir -p $APP_HOME
    
    
    WORKDIR $APP_HOME
    
    
    # Copy the output from builder image to main image
    COPY --from=builder /app ./
    
    
    RUN chown -R $APP_USER:$APP_USER $APP_HOME
    
    
    USER $APP_USER
    
    
    # Run the sync agent executable by default when the container starts.
    ENTRYPOINT ["./main"]
    


    But now I am getting a different error.

     => ERROR [builder 10/10] RUN CGO_ENABLED=1 go build -o main .                                                                    2.3s
    ------
     > [builder 10/10] RUN CGO_ENABLED=1 go build -o main .:
    #18 2.250 # solace.dev/go/messaging/internal/ccsmp
    #18 2.250 /usr/bin/ld: /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/ccsmp/lib/linux/libsolclient.a(solClient.o): Relocations in generic ELF (EM: 62)
    #18 2.250 /usr/bin/ld: /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/ccsmp/lib/linux/libsolclient.a(solClient.o): Relocations in generic ELF (EM: 62)
    #18 2.250 /usr/bin/ld: /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/ccsmp/lib/linux/libsolclient.a(solClient.o): Relocations in generic ELF (EM: 62)
    #18 2.250 /usr/bin/ld: /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/ccsmp/lib/linux/libsolclient.a(solClient.o): Relocations in generic ELF (EM: 62)
    #18 2.250 /usr/bin/ld: /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/ccsmp/lib/linux/libsolclient.a(solClient.o): Relocations in generic ELF (EM: 62)
    #18 2.250 /usr/bin/ld: /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/ccsmp/lib/linux/libsolclient.a(solClient.o): Relocations in generic ELF (EM: 62)
    #18 2.250 /usr/bin/ld: /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/ccsmp/lib/linux/libsolclient.a(solClient.o): Relocations in generic ELF (EM: 62)
    #18 2.250 /usr/bin/ld: /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/ccsmp/lib/linux/libsolclient.a(solClient.o): Relocations in generic ELF (EM: 62)
    #18 2.250 /usr/bin/ld: /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/ccsmp/lib/linux/libsolclient.a(solClient.o): Relocations in generic ELF (EM: 62)
    #18 2.250 /usr/bin/ld: /go/pkg/mod/solace.dev/go/messaging@v1.0.1/internal/ccsmp/lib/linux/libsolclient.a: error adding symbols: file in wrong format
    #18 2.250 collect2: error: ld returned 1 exit status
    ------
    executor failed running [/bin/sh -c CGO_ENABLED=1 go build -o main .]: exit code: 2
    
  • subhoatg
    subhoatg Member Posts: 17

    Update : I previously ran it on an m1 Mac. On an Intel Mac, it is working fine.

  • amackenzie
    amackenzie Member, Employee Posts: 260 Solace Employee

    That seems like it could do with not supporting M1 Apple chips... yet. Again, it's coming soon, but we do not yet support M1 chips.

  • subhoatg
    subhoatg Member Posts: 17

    @amackenzie thanks. Do you have any timeline for support of alpine images ?

  • amackenzie
    amackenzie Member, Employee Posts: 260 Solace Employee

    @murat are you able to comment on the Alpine and M1 timelines?

  • murat
    murat Member, Employee Posts: 20 Solace Employee

    Hi @subhoatg ,

    Support of Alpine and M1 will be coming towards the end of this year. I'll be sure to make a community post when it happens so be in the lookout for that announcement.

  • cpolzer
    cpolzer Member Posts: 1
    edited February 2023 #10

    Hello,

    may I ask if we are now enabled to use Alpine with MUSL to statically link our dependencies?

    I think static linking with glibc will also cause licencing issues if one plans to distribute a piece of software to customers thats using solace internally ?

  • subhoatg
    subhoatg Member Posts: 17

    Hi @murat

    can you please let us know the status ?


    Regards,

    Subhankar

  • murat
    murat Member, Employee Posts: 20 Solace Employee

    Hi @subhoatg ,

    We had announced the C API support for Alpine (which is required for the Go API) and that announcement was made here: https://solace.community/discussion/1498/pubsub-messaging-api-for-c-alpine-linux-support

    As for the Go API it officially supports Alpine Linux as of version 1.1.0 (with the current version being v.1.2.0)

    This concludes support for Alpine, however support for Mac M series is still pending and expected on or before June 2023. Similarly to the the Alpine support, I will be making another community post once it is released for general awareness.

    Thank you,

    MV

  • subhoatg
    subhoatg Member Posts: 17

    Hi @murat


    that’s great. I missed the announcement somehow. Do you also have windows support in pipeline ?

  • murat
    murat Member, Employee Posts: 20 Solace Employee

    Hi @subhoatg ,

    Support for Windows is in the pipeline, but we do not have any dates that we can share just yet.


    Cheers,

    MV