Skip to content

Commit da70254

Browse files
committed
Initial commit
0 parents  commit da70254

File tree

10 files changed

+218
-0
lines changed

10 files changed

+218
-0
lines changed

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
/.dockerignore
3+
/.git
4+
/.gitattributes
5+
/.gitignore
6+
/build
7+
/Dockerfile
8+
/LICENSE
9+
/node_modules
10+
/README.md

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# npm
2+
/node_modules
3+
4+
# Suri
5+
/build

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# syntax=docker/dockerfile:1
2+
3+
ARG NODE_VERSION=20
4+
5+
FROM node:${NODE_VERSION}-alpine AS build
6+
WORKDIR /suri
7+
RUN --mount=type=bind,source=package.json,target=package.json \
8+
--mount=type=bind,source=package-lock.json,target=package-lock.json \
9+
--mount=type=cache,target=/root/.npm \
10+
npm ci --include=dev
11+
COPY . .
12+
RUN npm run build
13+
14+
FROM scratch AS export
15+
COPY --from=build /suri/build .
16+
17+
FROM lipanski/docker-static-website:latest
18+
COPY --from=export . .

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Justin Stayton
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<h1 align="center" width="100%">
2+
<img src="https://raw.githubusercontent.com/surishortlink/suri/HEAD/logo.png" width="200" alt="Suri" />
3+
</h1>
4+
5+
<h3 align="center" width="100%">
6+
<i>Your own short links as an easily deployed static site with Docker</i>
7+
</h3>
8+
9+
You're viewing a template repository tailored for deploying Suri with Docker.
10+
That could be on a cloud platform that supports Docker container images, or just
11+
on your own machine. Head over to
12+
[the main repository](https://github.com/surishortlink/suri) to learn more about
13+
Suri, including additional deployment options.
14+
15+
## Setup: Step By Step
16+
17+
1. Hit the "Use this template" button above and then "Create a new repository".
18+
Fill in the required details to create a new repository based on this one.
19+
2. Make sure you have Docker installed and running.
20+
[Docker Desktop](https://www.docker.com/products/docker-desktop) is an easy
21+
way to get started on your own machine.
22+
3. Build a Docker image named `suri` from the [`Dockerfile`](Dockerfile):
23+
24+
```bash
25+
docker build --tag suri .
26+
```
27+
28+
This uses
29+
[docker-static-website](https://github.com/lipanski/docker-static-website) to
30+
produce a very small image.
31+
32+
4. Start a new container using the image, which serves the static site on port
33+
`3000`:
34+
35+
```bash
36+
docker run --interactive --tty --rm --init --publish 3000:3000 suri
37+
```
38+
39+
### Build Only, Don't Serve
40+
41+
If you're just looking to build the static site, but not serve it, you can
42+
change the `docker build` command to export the `build` directory from the
43+
Docker image to your host machine:
44+
45+
```bash
46+
docker build --target=export --output=build --tag suri .
47+
```
48+
49+
Keep in mind that this won't remove any existing files in the `build` directory
50+
on your host machine, so you may want to delete the directory beforehand.
51+
52+
## How It Works
53+
54+
### Manage Links
55+
56+
At the heart of Suri is the [`links.json`](src/links.json) file, located in the
57+
`src` directory, where you manage your links. All of the template repositories
58+
include this file seeded with a few examples:
59+
60+
```json
61+
{
62+
"/": "https://www.youtube.com/watch?v=CsHiG-43Fzg",
63+
"1": "https://fee.org/articles/the-use-of-knowledge-in-society/",
64+
"gh": "https://github.com/surishortlink/suri"
65+
}
66+
```
67+
68+
It couldn't be simpler: the key is the "short link" path that gets redirected,
69+
and the value is the target URL. Keys can be as short or as long as you want,
70+
using whatever mixture of characters you want. `/` is a special entry for
71+
redirecting the root path.
72+
73+
### Build Static Site
74+
75+
Suri ships with a `suri` executable file that generates the static site from the
76+
`links.json` file. The static site is output to a directory named `build`.
77+
78+
All of the template repositories are configured with a `build` script that
79+
invokes this executable, making the command you run simple:
80+
81+
```bash
82+
npm run build
83+
```
84+
85+
When you make a change to the `links.json` file, simply re-run this command to
86+
re-generate the static site, which can then be re-deployed.
87+
88+
### Config
89+
90+
Configuration is handled through the [`suri.config.json`](suri.config.json) file
91+
in the root directory. There is only one option at this point:
92+
93+
| Option | Description | Type | Default |
94+
| ------ | ------------------------------------------------------------------ | ------- | ------- |
95+
| `js` | Whether to redirect with JavaScript instead of a `<meta>` refresh. | Boolean | `false` |
96+
97+
### Public Directory
98+
99+
Finally, any files in the `public` directory will be copied over to the `build`
100+
directory without modification when the static site is built. This can be useful
101+
for files like `favicon.ico` or `robots.txt` (that said, Suri provides sensible
102+
defaults for both).

package-lock.json

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@surishortlink/deploy-docker",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module",
6+
"description": "A template repository tailored for deploying Suri with Docker",
7+
"homepage": "https://github.com/surishortlink/suri-deploy-docker#readme",
8+
"bugs": "https://github.com/surishortlink/suri-deploy-docker/issues",
9+
"license": "MIT",
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/surishortlink/suri-deploy-docker.git"
13+
},
14+
"scripts": {
15+
"build": "suri"
16+
},
17+
"devDependencies": {
18+
"@surishortlink/suri": "^1"
19+
},
20+
"engines": {
21+
"node": ">=18"
22+
}
23+
}

src/links.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"/": "https://github.com/jstayton/suri",
3+
"1": "https://fee.org/articles/the-use-of-knowledge-in-society/",
4+
"tw": "https://twitter.com"
5+
}

suri.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"js": false
3+
}

0 commit comments

Comments
 (0)