Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] arm64 / aarch64 support for docker #1220

Open
oskardotglobal opened this issue Dec 24, 2022 · 9 comments
Open

[FEATURE] arm64 / aarch64 support for docker #1220

oskardotglobal opened this issue Dec 24, 2022 · 9 comments

Comments

@oskardotglobal
Copy link

I was able to get Pufferpanel to run on a Oracle Cloud Ampere A1 machine with the following Dockerfile:

###
# Builder container
###
FROM node:16-alpine AS node
FROM golang:1.19-alpine AS builder

COPY --from=node /usr/lib /usr/lib
COPY --from=node /usr/local/share /usr/local/share
COPY --from=node /usr/local/lib /usr/local/lib
COPY --from=node /usr/local/include /usr/local/include
COPY --from=node /usr/local/bin /usr/local/bin

ARG tags=none
ARG version=devel
ARG sha=devel
ARG goproxy
ARG npmproxy
ARG swagversion=1.8.8

ENV CGOENABLED=1

ENV npm_config_registry=$npmproxy
ENV GOPROXY=$goproxy

RUN /bin/sh -c "go version && \
    apk add --update --no-cache gcc musl-dev git curl make gcc g++ && \
    mkdir /pufferpanel && \
    wget https://github.com/swaggo/swag/releases/download/v${swagversion}/swag_${swagversion}_Linux_aarch64.tar.gz && \
    mkdir -p ~/go/bin && \
    tar -zxf swag*.tar.gz -C ~/go/bin && \
    rm -rf swag*.tar.gz"

WORKDIR /build

COPY go.mod go.sum ./
RUN /bin/sh -c "go mod download && go mod verify"

COPY . .

RUN /bin/sh -c "~/go/bin/swag init -o web/swagger -g web/loader.go"
RUN /bin/sh -c "go build -v -buildvcs=false -ldflags \"-X 'github.com/pufferpanel/pufferpanel/v2.Hash=$sha' -X 'github.com/pufferpanel/pufferpanel/v2.Version=$version'\" -o /pufferpanel/pufferpanel github.com/pufferpanel/pufferpanel/v2/cmd"

RUN /bin/sh -c "mv assets/email /pufferpanel/email && \
    cd client && \
    npm install && \
    npm run build && \
    mv dist /pufferpanel/www/"


###
# Generate final image
###

FROM alpine
COPY --from=builder /pufferpanel /pufferpanel

EXPOSE 8080 5657

RUN /bin/sh -c "mkdir -p /etc/pufferpanel && \
    mkdir -p /var/lib/pufferpanel"

ENV PUFFER_LOGS=/etc/pufferpanel/logs \
    PUFFER_PANEL_TOKEN_PUBLIC=/etc/pufferpanel/public.pem \
    PUFFER_PANEL_TOKEN_PRIVATE=/etc/pufferpanel/private.pem \
    PUFFER_PANEL_DATABASE_DIALECT=sqlite3 \
    PUFFER_PANEL_DATABASE_URL="file:/etc/pufferpanel/pufferpanel.db?cache=shared" \
    PUFFER_DAEMON_SFTP_KEY=/etc/pufferpanel/sftp.key \
    PUFFER_DAEMON_DATA_CACHE=/var/lib/pufferpanel/cache \
    PUFFER_DAEMON_DATA_SERVERS=/var/lib/pufferpanel/servers \
    PUFFER_DAEMON_DATA_MODULES=/var/lib/pufferpanel/modules \
    PUFFER_DAEMON_DATA_BINARIES=/var/lib/pufferpanel/binaries \
    GIN_MODE=release

ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk

RUN /bin/sh -c "echo 'https://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories && \
    apk update"

RUN /bin/sh -c "apk add --no-cache openjdk17 && \
    ln -sfn /usr/lib/jvm/java-17-openjdk/bin/java /usr/bin/java && \
    ln -sfn /usr/lib/jvm/java-17-openjdk/bin/javac /usr/bin/javac && \
    ln -sfn /usr/lib/jvm/java-17-openjdk/bin/java /usr/bin/java17 && \
    ln -sfn /usr/lib/jvm/java-17-openjdk/bin/javac /usr/bin/javac17 && \
    echo 'Testing Javac 17 path' && \
    javac17 -version && \
    echo 'Testing Java 17 path' && \
    java17 -version && \
    echo 'Testing java path' && \
    java -version && \
    echo 'Testing javac path' && \
    javac -version"

# Cleanup
RUN /bin/sh -c "rm -rf /var/cache/apk/*"

WORKDIR /pufferpanel

ENTRYPOINT ["/pufferpanel/pufferpanel"]
CMD ["run"]

I had to split up some commands because else it wouldn't run at all. I also replaced swag with the aarch64 version. I then built the image manually. It works perfectly, so it is definetly possible to add officially supported arm64 images.

@LordRalex
Copy link
Member

It is possible, that's not the issue.

The issue is that currently, Github Actions don't run native ARM workers yet, and so it is very slow to build the arm-based images on our current CI pipeline.

I'm not in the position nor want to run a dedicated CI system just for this pipeline.

@fox8091
Copy link

fox8091 commented Jan 8, 2023

Could the official Dockerfile at least be updated to allow building on arm64 without requiring a patch?

@oskardotglobal
Copy link
Author

It is possible, that's not the issue.

The issue is that currently, Github Actions don't run native ARM workers yet, and so it is very slow to build the arm-based images on our current CI pipeline.

I'm not in the position nor want to run a dedicated CI system just for this pipeline.

Since aarch64-images are a niche anyways I am not talking about providing pre-built images but rather a Dockerfile. If there were an official Dockerfile I and lots of people would be able to test it on different machines.

@oskardotglobal
Copy link
Author

Could the official Dockerfile at least be updated to allow building on arm64 without requiring a patch?

I had to change a lot to get this to build, some of them are things I don't properly understand why they work.

Since the aarch64 Dockerfile wouldn't be compatible with x86 systems, I would recommend moving the Dockerfile to a Dockerfile.amd64 and adding a Dockerfile.aarch64

@RedStalker
Copy link

Thanks for the Docker file! I'm also runnig the server on a Oracle Cloud

@3Dieuwer
Copy link

Hi, I haven't yet build a image in docker (portainer) myself and i am struggeling to use your code, i seem to get a error at step 19/36 "COPY failed: file not found in build context or excluded by .dockerignore: stat go.mod: file does not exist" Any idea what I can do to make it run?
FYI, stil kinda noob at this, so you might need to thin it down for me real bad xD
Thanks!

@oskardotglobal
Copy link
Author

@3Dieuwer Building images with portainer is not really possible.

  1. Clone this repository and rename the folder to how you want your stack to be named
  2. Copy in the dockerfile (maybe as Dockerfile.aarch64 - then you have to specify the dockerfile in the compose file though - or just overwrite the other one)
  3. Copy your compose file into the directory
  4. Run docker compose build (or docker-compose build if you run an older docker version)
  5. Deploy the compose stack via portainer with the same name as the folder

If it doesn't work, shoot me an e-mail to hello@oskar.global

@oskardotglobal
Copy link
Author

Also, @LordRalex, I would be able to distribute pre-build images myself, right? That should comply with the Apache License

@oskardotglobal
Copy link
Author

So I got the docker images to build with github actions, don't know if its reasonably usable since every build takes ~45min. For anyone who needs it, you can now find unofficial, pre-build images by me @ https://github.com/oskardotglobal/pufferpanel-docker-arm/pkgs/container/pufferpanel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants