Golang based Solace client in Docker

subhoatg
subhoatg Member Posts: 15

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/[email protected]/pkg/solace/subcode/subcode.go:41:15: undefined: ccsmp.SolClientSubCodeToString
#19 0.251 /go/pkg/mod/solace.dev/go/[email protected]/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/[email protected]/internal/impl/constants/default_properties.go:35:8: undefined: ccsmp.SolClientSessionPropTopicDispatch
#19 0.289 /go/pkg/mod/solace.dev/go/[email protected]/internal/impl/constants/default_properties.go:36:8: undefined: ccsmp.SolClientSessionPropSendBlocking
#19 0.289 /go/pkg/mod/solace.dev/go/[email protected]/internal/impl/constants/default_properties.go:37:8: undefined: ccsmp.SolClientSessionPropReapplySubscriptions
#19 0.289 /go/pkg/mod/solace.dev/go/[email protected]/internal/impl/constants/default_properties.go:38:8: undefined: ccsmp.SolClientSessionPropIgnoreDupSubscriptionError
#19 0.289 /go/pkg/mod/solace.dev/go/[email protected]/internal/impl/constants/default_properties.go:39:8: undefined: ccsmp.SolClientSessionPropReconnectRetries
#19 0.289 /go/pkg/mod/solace.dev/go/[email protected]/internal/impl/constants/default_properties.go:40:8: undefined: ccsmp.SolClientSessionPropGuaranteedWithWebTransport
#19 0.289 /go/pkg/mod/solace.dev/go/[email protected]/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: 191 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: 191 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: 15

    @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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]1.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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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: 15

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

  • amackenzie
    amackenzie Member, Employee Posts: 191 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: 15

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

  • amackenzie
    amackenzie Member, Employee Posts: 191 Solace Employee

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

  • murat
    murat Member, Employee Posts: 7 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.