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

ci(actions): add release workflow #437

Merged
merged 2 commits into from
Aug 16, 2024
Merged
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
121 changes: 49 additions & 72 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,55 @@
name: Build for Release
on: [release]
name: Publish containers for release

on:
release:
types: [published]

jobs:
release-linux-386:
name: release linux/386
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: compile and release
uses: ngs/go-release.action@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: '386'
GOOS: linux
EXTRA_FILES: 'license'
release-linux-amd64:
name: release linux/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: compile and release
uses: ngs/go-release.action@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: amd64
GOOS: linux
EXTRA_FILES: 'license'
release-darwin-amd64:
name: release darwin/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: compile and release
uses: ngs/go-release.action@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: amd64
GOOS: darwin
EXTRA_FILES: 'license'
release-windows-386:
name: release windows/386
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: compile and release
uses: ngs/go-release.action@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: '386'
GOOS: windows
EXTRA_FILES: 'license'
release-windows-amd64:
name: release windows/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: compile and release
uses: ngs/go-release.action@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: amd64
GOOS: windows
EXTRA_FILES: 'license'
docker:
name: publish to docker
push_to_registries:
name: Push Docker image to multiple registries
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
id-token: write
steps:
- uses: actions/checkout@master
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
images: |
spacebinorg/spirit
ghcr.io/${{ github.repository }}

- name: Build and push Docker images
uses: docker/build-push-action@v3.2.0
id: push
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
125 changes: 65 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ Spacebin is a modern Pastebin server implemented in Go and maintained by Luke Wh
Pastebins are a type of online content storage service where users can store plain text document, e.g. program source code. For more information and the history of Pastebin see Wikipedia's [article on them](https://en.wikipedia.org/wiki/Pastebin).

**Features:**
- [X] 99% self-contained: only requires Postgres to run.
- [X] Raw text and file uploading
- [X] Phrase and random string identifiers.
- [X] Custom documents that are always available.
- [X] Configurable ratelimiting, expiration, compression, etc.
- [X] Modern, JavaScript-free user interface
- [X] Syntax highlighting for all the most popular languages and Raw text mode
- [ ] Password-protected encrypted pastes
- [ ] SQLite Support
- [ ] Paste collections
- [ ] Reader view mode (Markdown is formatted and word wraping is enbaled)
- [ ] QR Codes
- [ ] Image uploading

> [!TIP]
> **Try our public online version at [https://spaceb.in](https://spaceb.in)**!
- [x] 99% self-contained: only requires Postgres to run.
- [x] Raw text and file uploading
- [x] Phrase and random string identifiers.
- [x] Custom documents that are always available.
- [x] Configurable ratelimiting, expiration, compression, etc.
- [x] Modern, JavaScript-free user interface
- [x] Syntax highlighting for all the most popular languages and Raw text mode
- [ ] Password-protected encrypted pastes
- [ ] SQLite Support
- [ ] Paste collections
- [ ] Reader view mode (Markdown is formatted and word wrapping is enabled)
- [ ] QR Codes
- [ ] Image uploading

> [!TIP] > **Try our public online version at [https://spaceb.in](https://spaceb.in)**!

## Table of Contents

Expand Down Expand Up @@ -64,8 +64,7 @@ $ sudo docker run -d -p 80:9000 spacebinorg/spirit

#### Manually

> [!IMPORTANT]
> **Requires: [Git](https://git-scm.com/downloads), [Go 1.22.4](https://go.dev/doc/install), [GNU Makefile](https://www.gnu.org/software/make/#download), and a [PostgreSQL](https://www.postgresql.org/download/) [server](https://m.do.co/c/beaf675c3e00).**
> [!IMPORTANT] > **Requires: [Git](https://git-scm.com/downloads), [Go 1.22.4](https://go.dev/doc/install), [GNU Makefile](https://www.gnu.org/software/make/#download), and a [PostgreSQL](https://www.postgresql.org/download/) [server](https://m.do.co/c/beaf675c3e00).**

```sh
# Clone the Github repository
Expand All @@ -83,19 +82,19 @@ $ SPIRIT_CONNECTION_URI="<your PostgreSQL instance URI>" ./bin/spirit

#### Environment Variables

| Variable Name | Type | Default | Description |
|-------------------------|-----------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| `SPIRIT_HOST` | String | `0.0.0.0` | Host address to listen on |
| `SPIRIT_PORT` | Int | `9000` | HTTP port to listen on |
| `SPIRIT_RATELIMITER` | String | `200x5` | Requests allowed per second before the user is ratelimited |
| `SPIRIT_CONNECTION_URI` | String | **Required** | [PostgreSQL Database URI String](https://stackoverflow.com/questions/3582552/what-is-the-format-for-the-postgresql-connection-string-url#20722229) |
| `SPIRIT_HEADLESS` | Bool | `False` | Enables/disables the web interface |
| `SPIRIT_ANALYTICS` | String | `""` | `<script>` tag for analytics (leave blank to disable) |
| `SPIRIT_ID_LENGTH` | Int | `8` | Length for document IDs |
| `SPIRIT_ID_TYPE` | `"key"` or `"phrase"` | `key` | Format of IDs: `key` is a random string of letters and [`phrase` is a combination of words](https://github.com/lukewhrit/phrase) |
| `SPIRIT_MAX_SIZE` | Int | `400000` | Max allowed size of a document in bytes |
| `SPIRIT_EXPIRATION_AGE` | Int64 | `720` | Amount of time to expire documents after |
| `SPIRIT_DOCUMENTS` | []String | `[]` | List of any custom documents to serve |
| Variable Name | Type | Default | Description |
| ----------------------- | --------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SPIRIT_HOST` | String | `0.0.0.0` | Host address to listen on |
| `SPIRIT_PORT` | Int | `9000` | HTTP port to listen on |
| `SPIRIT_RATELIMITER` | String | `200x5` | Requests allowed per second before the user is ratelimited |
| `SPIRIT_CONNECTION_URI` | String | **Required** | [PostgreSQL Database URI String](https://stackoverflow.com/questions/3582552/what-is-the-format-for-the-postgresql-connection-string-url#20722229) |
| `SPIRIT_HEADLESS` | Bool | `False` | Enables/disables the web interface |
| `SPIRIT_ANALYTICS` | String | `""` | `<script>` tag for analytics (leave blank to disable) |
| `SPIRIT_ID_LENGTH` | Int | `8` | Length for document IDs |
| `SPIRIT_ID_TYPE` | `"key"` or `"phrase"` | `key` | Format of IDs: `key` is a random string of letters and [`phrase` is a combination of words](https://github.com/lukewhrit/phrase) |
| `SPIRIT_MAX_SIZE` | Int | `400000` | Max allowed size of a document in bytes |
| `SPIRIT_EXPIRATION_AGE` | Int64 | `720` | Amount of time to expire documents after |
| `SPIRIT_DOCUMENTS` | []String | `[]` | List of any custom documents to serve |

> [!WARNING]
> Environment variables for Spacebin are prefixed with `SPIRIT_`. They will be updated to `SPACEBIN_` in the next major version.
Expand All @@ -106,6 +105,8 @@ $ SPIRIT_CONNECTION_URI="<your PostgreSQL instance URI>" ./bin/spirit

To use Spacebin on the web, our team provides a web app. You can access the web app at **[spaceb.in](https://spaceb.in)**. You must use `https://spaceb.in/api` to access the API routes.

A version of spacebin that is built directly from the `develop` branch is also available at \*\*[staging.spaceb.in](https://staging.spaceb.in)

#### CLI

Since Spirit supports `multipart/form-data` uploads, it's extremely easy to use on the command line via `curl`. The scripts also use `jq` so that you can get a machine-readable version of the document's ID, instead of a lengthy JSON object.
Expand All @@ -126,50 +127,54 @@ curl -v -F content=@helloworld.txt https://spaceb.in/ | jq payload.id

There are three primary API routes to: create a document, fetch a documents text content in JSON format, and fetch a documents **plain text** content.

* `/api/`: Create Document
* Accepts JSON and multipart/form-data
* For both formats, include document content in a `content` field
* Only accepts POST requests
* Instances are able to specify a maximum document length.
* `spaceb.in` uses a 4MB maximum size.
* Successful requests return a JSON body with the following format:
- `/api/`: Create Document
- Accepts JSON and multipart/form-data
- For both formats, include document content in a `content` field
- Only accepts POST requests
- Instances are able to specify a maximum document length.
- `spaceb.in` uses a 4MB maximum size.
- Successful requests return a JSON body with the following format:

```json
{
"error": "",
"payload": {
"id": "WfwKGJfs",
"content": "hello",
"created_at": "2023-08-06T00:01:33.143532-04:00",
"updated_at": "2023-08-06T00:01:33.143532-04:00"
}
"error": "",
"payload": {
"id": "WfwKGJfs",
"content": "hello",
"created_at": "2023-08-06T00:01:33.143532-04:00",
"updated_at": "2023-08-06T00:01:33.143532-04:00"
}
}
```
* `/api/{document}`: Fetch Document
* `{document}` = Document ID
* Document ID lengths vary between instances. For `spaceb.in`, they will be exactly **8** characters.
* Upon successful request, returns a JSON body with the following format:

- `/api/{document}`: Fetch Document
- `{document}` = Document ID
- Document ID lengths vary between instances. For `spaceb.in`, they will be exactly **8** characters.
- Upon successful request, returns a JSON body with the following format:

```json
{
"error": "",
"payload": {
"id": "WfwKGJfs",
"content": "hello",
"created_at": "2023-08-06T00:01:33.143532-04:00",
"updated_at": "2023-08-06T00:01:33.143532-04:00"
}
"error": "",
"payload": {
"id": "WfwKGJfs",
"content": "hello",
"created_at": "2023-08-06T00:01:33.143532-04:00",
"updated_at": "2023-08-06T00:01:33.143532-04:00"
}
}
```
* `/api/{document}/raw`: Fetch Document - Raw
* `{document}` = Document ID
* Document ID lengths vary between instances. For `spaceb.in`, they will be exactly 8 characters
* Returns a `plain/text` file containing the content of the document.

- `/api/{document}/raw`: Fetch Document - Raw
- `{document}` = Document ID
- Document ID lengths vary between instances. For `spaceb.in`, they will be exactly 8 characters
- Returns a `plain/text` file containing the content of the document.

> [!TIP]
> There are two additional non-API routes that are documented: `/ping`: returns a 200 OK if the service is online, and `/config`: returns a JSON body with the instances configuration settings.

## Credits

Spacebin is a project designed and maintained by Luke Whritenour. Spacebin started out as a fork of [hastebin](https://github.com/toptal/haste-server). Although it no longer contains *any* code from the original, we'd like to acknowledge our roots regardless.
Spacebin is a project designed and maintained by Luke Whritenour. Spacebin started out as a fork of [hastebin](https://github.com/toptal/haste-server). Although it no longer contains _any_ code from the original, we'd like to acknowledge our roots regardless.

Spacebin itself is built using Go and various libraries (i.e. [Chi](https://github.com/go-chi/chi), [pq](https://github.com/lib/pq), [Ozzo Validation](https://github.com/go-ozzo/ozzo-validation), [Cron](https://github.com/robfig/cron), [env](https://github.com/caarlos0/env)).

Expand Down
Loading