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

docs: add docker option to static hosting page #1648

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions docs/guide/hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,55 @@ 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 build and 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
```
34 changes: 0 additions & 34 deletions docs/guide/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `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` as a static website via services such as [GitHub Pages](https://tangramor.github.io/slidev_docker/) or GitLab Pages.

Since in GitHub Pages the URL may contain subfolders, you may use `--base=/<subfolder>/` option during the build process, such as `docker exec -i slidev npx slidev build --base=/slidev_docker/`.

To avoid the Jekyll build process, you'll need to add an empty file `.nojekyll`.

#### Host via docker

You can also host Slidev yourself via 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 [tangramor/slidev_docker](https://github.com/tangramor/slidev_docker) for more details.

## Command Line Interface (CLI)
Expand Down
Loading