Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jstayton committed Aug 28, 2024
0 parents commit da70254
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.DS_Store
/.dockerignore
/.git
/.gitattributes
/.gitignore
/build
/Dockerfile
/LICENSE
/node_modules
/README.md
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# npm
/node_modules

# Suri
/build
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# syntax=docker/dockerfile:1

ARG NODE_VERSION=20

FROM node:${NODE_VERSION}-alpine AS build
WORKDIR /suri
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \
npm ci --include=dev
COPY . .
RUN npm run build

FROM scratch AS export
COPY --from=build /suri/build .

FROM lipanski/docker-static-website:latest
COPY --from=export . .
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2024 Justin Stayton

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
102 changes: 102 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<h1 align="center" width="100%">
<img src="https://raw.githubusercontent.com/surishortlink/suri/HEAD/logo.png" width="200" alt="Suri" />
</h1>

<h3 align="center" width="100%">
<i>Your own short links as an easily deployed static site with Docker</i>
</h3>

You're viewing a template repository tailored for deploying Suri with Docker.
That could be on a cloud platform that supports Docker container images, or just
on your own machine. Head over to
[the main repository](https://github.com/surishortlink/suri) to learn more about
Suri, including additional deployment options.

## Setup: Step By Step

1. Hit the "Use this template" button above and then "Create a new repository".
Fill in the required details to create a new repository based on this one.
2. Make sure you have Docker installed and running.
[Docker Desktop](https://www.docker.com/products/docker-desktop) is an easy
way to get started on your own machine.
3. Build a Docker image named `suri` from the [`Dockerfile`](Dockerfile):

```bash
docker build --tag suri .
```

This uses
[docker-static-website](https://github.com/lipanski/docker-static-website) to
produce a very small image.

4. Start a new container using the image, which serves the static site on port
`3000`:

```bash
docker run --interactive --tty --rm --init --publish 3000:3000 suri
```

### Build Only, Don't Serve

If you're just looking to build the static site, but not serve it, you can
change the `docker build` command to export the `build` directory from the
Docker image to your host machine:
```bash
docker build --target=export --output=build --tag suri .
```
Keep in mind that this won't remove any existing files in the `build` directory
on your host machine, so you may want to delete the directory beforehand.

## How It Works

### Manage Links

At the heart of Suri is the [`links.json`](src/links.json) file, located in the
`src` directory, where you manage your links. All of the template repositories
include this file seeded with a few examples:

```json
{
"/": "https://www.youtube.com/watch?v=CsHiG-43Fzg",
"1": "https://fee.org/articles/the-use-of-knowledge-in-society/",
"gh": "https://github.com/surishortlink/suri"
}
```

It couldn't be simpler: the key is the "short link" path that gets redirected,
and the value is the target URL. Keys can be as short or as long as you want,
using whatever mixture of characters you want. `/` is a special entry for
redirecting the root path.
### Build Static Site
Suri ships with a `suri` executable file that generates the static site from the
`links.json` file. The static site is output to a directory named `build`.
All of the template repositories are configured with a `build` script that
invokes this executable, making the command you run simple:
```bash
npm run build
```
When you make a change to the `links.json` file, simply re-run this command to
re-generate the static site, which can then be re-deployed.
### Config
Configuration is handled through the [`suri.config.json`](suri.config.json) file
in the root directory. There is only one option at this point:
| Option | Description | Type | Default |
| ------ | ------------------------------------------------------------------ | ------- | ------- |
| `js` | Whether to redirect with JavaScript instead of a `<meta>` refresh. | Boolean | `false` |
### Public Directory
Finally, any files in the `public` directory will be copied over to the `build`
directory without modification when the static site is built. This can be useful
for files like `favicon.ico` or `robots.txt` (that said, Suri provides sensible
defaults for both).
31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@surishortlink/deploy-docker",
"version": "1.0.0",
"private": true,
"type": "module",
"description": "A template repository tailored for deploying Suri with Docker",
"homepage": "https://github.com/surishortlink/suri-deploy-docker#readme",
"bugs": "https://github.com/surishortlink/suri-deploy-docker/issues",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/surishortlink/suri-deploy-docker.git"
},
"scripts": {
"build": "suri"
},
"devDependencies": {
"@surishortlink/suri": "^1"
},
"engines": {
"node": ">=18"
}
}
5 changes: 5 additions & 0 deletions src/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"/": "https://github.com/jstayton/suri",
"1": "https://fee.org/articles/the-use-of-knowledge-in-society/",
"tw": "https://twitter.com"
}
3 changes: 3 additions & 0 deletions suri.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"js": false
}

0 comments on commit da70254

Please sign in to comment.