From 668e032b95f197d494fc50cc6cfb9b7df2711096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Korde=C5=BE?= Date: Mon, 3 Jun 2024 11:19:02 +0200 Subject: [PATCH 1/3] Add docker option to hosting page --- docs/guide/hosting.md | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/docs/guide/hosting.md b/docs/guide/hosting.md index 74fe27bfb4..437fe53ce9 100644 --- a/docs/guide/hosting.md +++ b/docs/guide/hosting.md @@ -195,3 +195,65 @@ jobs: - In your repository, go to Settings>Pages. Under "Build and deployment", select "GitHub Actions". - Finally, after all workflows are executed, a link to the slides should appear under Settings>Pages. + +### Docker + +To deploy your slides in a Docker container: + +- Create a `.dockerignore` file in your project root with the following content. + +```dockerignore +node_modules +dist +``` + +- Create a `.htaccess` file in your project root with the following content. + +```apache +RewriteEngine On +RewriteBase / +RewriteRule ^index.html$ - [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . /index.html [L] +``` + +- Create a `Dockerfile` in your project root with the following content. + +```Dockerfile +FROM node:20 AS build + +WORKDIR /app + +COPY package*.json ./ + +RUN npm ci + +# Uncomment the following line if you are using `download: true` or `--download` +# RUN npx playwright install-deps + +COPY . . + +RUN npm build + +FROM httpd:2.4-alpine + +RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf && \ + sed -i 's#AllowOverride [Nn]one#AllowOverride All#' /usr/local/apache2/conf/httpd.conf + +COPY --from=build /app/dist/ /usr/local/apache2/htdocs/ + +COPY .htaccess /usr/local/apache2/htdocs/.htaccess +``` + +- Build the Docker image. + +```bash +$ docker build -t my-slidev . +``` + +- Run the Docker container (replace `8080` with the port you want to use). + +```bash +$ docker run -p 8080:80 my-slidev +``` From 10640241a5e766159e34649da7c1d23aec544f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Korde=C5=BE?= Date: Mon, 3 Jun 2024 22:06:51 +0200 Subject: [PATCH 2/3] Remove Docker static hosting from install.md --- docs/guide/install.md | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/docs/guide/install.md b/docs/guide/install.md index 9f7d2b3d26..33998c7a4f 100644 --- a/docs/guide/install.md +++ b/docs/guide/install.md @@ -97,40 +97,6 @@ And run the container: `docker run --name myslides --rm --user node -p 3030:3030 You can visit your slides at `http://localhost:3030/` -### Build hostable SPA (Single Page Application) - -Run command `docker exec -i slidev npx slidev build` on the running container `slidev`. It will generate static HTML files under `dist` folder. - -#### Host on Github Pages - -You can host `dist` in a static website such as [Github Pages](https://tangramor.github.io/slidev_docker/) or Gitlab Pages. - -Because in GitHub Pages, the URL may contain subfolders, you may use `--base=//` option during the build process, such as `docker exec -i slidev npx slidev build --base=/slidev_docker/`. - -To avoid the Jekyll build process, you need to add an empty file `.nojekyll`. - -#### Host by docker - -You can also host it by yourself with docker: - -```bash -docker run --name myslides --rm -p 80:80 -v ${PWD}/dist:/usr/share/nginx/html nginx:alpine -``` - -Or create a static image with the following Dockerfile: - -```Dockerfile -FROM nginx:alpine - -COPY dist /usr/share/nginx/html -``` - -Create the docker image: `docker build -t mystaticppt .` - -And run the container: `docker run --name myslides --rm -p 80:80 mystaticppt` - -You can visit your slides at http://localhost/ - Refer to the [tangramor/slidev_docker](https://github.com/tangramor/slidev_docker) for more details. ## Command Line Interface (CLI) From 8a46a8aba1fcb04bed6c705af8ae6ddfc030fc5a Mon Sep 17 00:00:00 2001 From: _Kerman Date: Thu, 13 Jun 2024 10:49:57 +0800 Subject: [PATCH 3/3] chore: update --- docs/guide/hosting.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/docs/guide/hosting.md b/docs/guide/hosting.md index 62c8414b64..3b0735e7f6 100644 --- a/docs/guide/hosting.md +++ b/docs/guide/hosting.md @@ -198,7 +198,7 @@ jobs: ### Docker -To deploy your slides in a Docker container: +To build and deploy your slides in a Docker container: - Create a `.dockerignore` file in your project root with the following content. @@ -222,27 +222,17 @@ RewriteRule . /index.html [L] ```Dockerfile FROM node:20 AS build - WORKDIR /app - COPY package*.json ./ - RUN npm ci - # Uncomment the following line if you are using `download: true` or `--download` # RUN npx playwright install-deps - COPY . . - RUN npm build - FROM httpd:2.4-alpine - RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf && \ sed -i 's#AllowOverride [Nn]one#AllowOverride All#' /usr/local/apache2/conf/httpd.conf - COPY --from=build /app/dist/ /usr/local/apache2/htdocs/ - COPY .htaccess /usr/local/apache2/htdocs/.htaccess ```