smocker-dev / smocker

Smocker is a simple and efficient HTTP mock server and proxy
https://smocker.dev
MIT License
1.16k stars 61 forks source link

Smocker image for arm64v8 missing. #237

Closed konstantinzolotarev closed 1 year ago

konstantinzolotarev commented 2 years ago

Could you please also release official ARM64v8 docker image ?

docker run -d \
  --restart=always \
  -p 8080:8080 \
  -p 8081:8081 \
  --name smocker \
  thiht/smocker
Unable to find image 'thiht/smocker:latest' locally
latest: Pulling from thiht/smocker
59bf1c3509f3: Pull complete
ec1217117c09: Pull complete
3ab0b2b28728: Pull complete
Digest: sha256:dd573c7fd5ca33bcbe80ff5e155564b85b4307af5ab9ff16b12101d5b1baeeec
Status: Downloaded newer image for thiht/smocker:latest
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
a3f8fb8ab6b382c80385b3526a10e31cb43a4434d2f958d23a6638d1ac7bb3ab
konstantinzolotarev commented 2 years ago

I tied to build image locally, but got lot of issues with parcel and it's dependencies. Will try to do something when will have some free time.

BTW. Thank you very much for your hard work and wanted to say that smocker really helped our team !

Thiht commented 2 years ago

Thanks for the kind words :)

On my side I tried creating a specific arm64v8 dockerfile (See Dockerfile.arm64v8 with the base images from the hub: https://hub.docker.com/u/arm64v8 but it didn't work (See build) and I'm not sure why. My guess is that I should try to build directly on an arm64 platform but I don't know if Github actions support that, I'll need to dig it. I also read some stuff about QEMU emulation with docker buildx but I fear that it'll be slow to build, and it's not really well documented

The github actions are promising though: https://github.com/docker/setup-buildx-action#with-qemu

andrcuns commented 2 years ago

It's fairly easy to build multiplatform images using buildx and github actions. Here is an example of a setup that doesn't require additional changes in Dockerfile (like custom arch argument to have a conditional flow for some binaries installations for example): https://github.com/andrcuns/allure-report-publisher/blob/main/.github/workflows/release.yml#L21

I could definitely benefit from arm image for local workflows on m1 macbook. Though the image does seem to work fine in emulation mode as well.

saw303 commented 1 year ago

First of all thank you very much for Smocker. It helps me a lot! 👍🏻

Building a multi-platform image is fairly simply, as mentioned in other comments. You simply use Docker buildx as shown below.

docker buildx build --no-cache --platform linux/amd64,linux/arm64/v8 --tag thiht/smocker:0.18.2-deleteme .

Nevertheless, I was not able to build the client in Docker due to issues with yarn.

Without knowing how the client works, I think it is not required to be build in a Docker multi-stage build, since it is not a binary.

When I adjusted the Dockerfile a bit and prebuilding the client on my machine I was able to successfully a multi-arch Docker image with Docker buildx.

FROM golang:1.18-alpine AS build-backend
RUN apk add --no-cache make
ARG VERSION=snapshot
ARG COMMIT
WORKDIR /go/src/github.com/Thiht/smocker
COPY go.mod go.sum ./
RUN go mod download
COPY Makefile main.go ./
COPY server/ ./server/
RUN make VERSION=$VERSION COMMIT=$COMMIT RELEASE=1 build

FROM alpine
WORKDIR /opt
EXPOSE 8080 8081
COPY --from=build-backend /go/src/github.com/Thiht/smocker/build/* /opt/
# pick pre-built the client from the local filesystem (adjust .dockerignore)
COPY build/* /opt/
CMD ["/opt/smocker"]

Not sure if this helps, but I thought it me be helpful.

If you consider to change the way the Docker image is built, I could provide a PR adjusting your GitHub Action workflow and add QEMU to it.

saw303 commented 1 year ago

@konstantinzolotarev you can still execute the Docker image but you need to install Rosetta 2. Add the parameter --platform=amd64 to your Docker run command.

docker run -d \
  --platform=amd64
  --restart=always \
  -p 8080:8080 \
  -p 8081:8081 \
  --name smocker \
  thiht/smocker
lukyer commented 1 year ago

See https://github.com/Thiht/smocker/pull/274

gwleclerc commented 1 year ago

Should be ok now that #274 and #282 are merged

saw303 commented 1 year ago

Excellent! It works. Thank you very much.