Ilyas-Codes / eCourse

A self-hosted SPA to simplify course creation and management
https://ecourse.pockethost.io
MIT License
452 stars 36 forks source link

Docker support. #3

Closed tiritibambix closed 9 months ago

tiritibambix commented 10 months ago

Hello. Your project looks really interesting. Is docker support in the works by any chance ?

Ilyas-Codes commented 10 months ago

Hey @tiritibambix thanks for checking out my project! I can't guarantee you that since I'm not very familiar with Docker and I'm quite busy with work right now, though I'd be happy if you'd like to submit a PR for that.

tiritibambix commented 10 months ago

I'd love to offer my help. Alas, all my attempts to learn Dockerfile have ended in abject failure 😅 I must confess I'm not the most computer-literate person in general ... I hope someone else will be able to take this over :) Take care.

grenskul commented 10 months ago

Made one . The default pocketbase executable you're shipping is mac so I had to replace it . Outside of that it's just following your prod build instructions I left it with port 80 and http cause I expect most people to put this behind a reverse proxy I also deleted the contents pb_data directory and deleted the client directory post build to save space

I built and pushed this to https://hub.docker.com/r/grenskul/ecourse but I'm probably not going to maintain this. It's a one off for a friend .

FROM node:20.11.0-buster

WORKDIR /

RUN git clone https://github.com/Ilyas-Codes/eCourse.git

WORKDIR /eCourse/client

RUN npm install 

RUN npm run build

RUN mv dist /eCourse/server/pb_public

RUN rm -r /eCourse/server/pb_data/*

RUN rm -r /eCourse/client

ADD pocketbase /eCourse/server/pocketbase

EXPOSE 80

CMD ["/eCourse/server/pocketbase", "serve", "--http=0.0.0.0:80"]
tiritibambix commented 10 months ago

Oh that's awesome. Thanks you, it is working great :)

For anyone interested, here's the docker-compose I used:

version: '3.3'
services:
    ecourse:
        container_name: ecourse
        volumes:
            - '/path/to/eCourse/data:/eCourse/server/pb_data'
        ports:
            - '${PORT}:80'
        image: grenskul/ecourse

Can't the image creation be automated ? I believe I heard something about it.

grenskul commented 10 months ago

It can be automated in many ways. But like I said this was a one off for a friend. Feel free to take that code and make your own docker hub image and to automate if you wish (or just rebuild and push whenever you make substantial changes). You have my permission to reuse, edit, publish, profit off, claim as your own or anything you want. It's just a couple of lines and it took 15 minutes to make. If you want to be extra nice you keep the same paths and port so my friend can switch over to the oficial image by just changing the image on his own config.

tiritibambix commented 10 months ago

You, Sir, are a gentleman and a scholar.

parasiteoflife commented 9 months ago

Please reopen this issue, this afaik has not been implemented yet

Ilyas-Codes commented 9 months ago

Thank you guys! just give me some time and I'll figure out this Docker stuff.

grenskul commented 9 months ago
FROM node:20.11.0-buster

WORKDIR /

RUN git clone https://github.com/Ilyas-Codes/eCourse.git

WORKDIR /eCourse/ui

RUN rm .env

RUN echo -b "VITE_PROD_PB_URL=http://127.0.0.1:8090" >> .env

RUN npm install 

RUN npm run build

RUN ln -s /eCourse/pb /eCourse/server

RUN rm -r /eCourse/pb/pb_public

RUN mv dist /eCourse/pb/pb_public/

RUN rm -r /eCourse/ui

ADD pocketbase /eCourse/pb/pocketbase

EXPOSE 80

CMD ["/eCourse/pb/pocketbase", "serve", "--http=0.0.0.0:80"]

Fixed it accounting for new pathing and added a symlink to be compatible with my older container for people that just want to update. Also if you pull grenskul/ecourse:test instead of the old one with no tag you will get the new version. To build this image you need the pocket base linux executable present in the same folder as the dockerfile

Ilyas-Codes commented 9 months ago

Hey guys, can you try out this Dockerfile and let me know how it went? (I don't think my computer is able to handle docker) if all goes well, I'll close the issue and add the Dockerfile to the repo. thank you!

FROM node:20.11.1-buster

WORKDIR /

RUN git clone https://github.com/Ilyas-Codes/eCourse.git

ARG PB_VERSION=0.21.3
ADD https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_amd64.zip /tmp/pb.zip
RUN unzip /tmp/pb.zip -d /eCourse/pb

WORKDIR /eCourse/ui

RUN sed -i 's/^VITE_PROD_PB_URL=.*/VITE_PROD_PB_URL=http:\/\/127.0.0.1:8090/' .env
RUN npm install
RUN npm run build
RUN mv dist /eCourse/pb/pb_public

EXPOSE 8090

CMD ["/eCourse/pb/pocketbase", "serve", "--http=0.0.0.0:8090"]
Cregennan commented 9 months ago

Hey guys, can you try out this Dockerfile and let me know how it went? (I don't think my computer is able to handle docker) if all goes well, I'll close the issue and add the Dockerfile to the repo. thank you!

Yes, it actually works

Ilyas-Codes commented 9 months ago

@Cregennan thank you, I will add it to the README now.