ci: add action
This commit is contained in:
parent
ee3220b87a
commit
24e305c8ff
3
.dockerignore
Normal file
3
.dockerignore
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
node_modules
|
||||
docs
|
||||
.yarn
|
||||
62
.gitea/workflows/publish.yml
Normal file
62
.gitea/workflows/publish.yml
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
name: Docker CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
node-version: 20.x
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
env:
|
||||
DOCKER_ORG: nzambello
|
||||
DOCKER_LATEST: nightly
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v4
|
||||
with:
|
||||
images: |
|
||||
nzambello/redirector
|
||||
labels: |
|
||||
org.label-schema.docker.cmd=docker run -d -p 8080:8080 nzambello/redirector
|
||||
flavor: latest=false
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=sha
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
|
||||
- name: Login to Container Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: ${{ gitea.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
nzambello/redirector:latest
|
||||
labels: $${{ steps.meta.outputs.labels }}
|
||||
|
|
@ -29,6 +29,7 @@ It loads configuration from environment variables:
|
|||
|
||||
- `REDIRECT_URL`: (**required**) the url to redirect to
|
||||
- `PERMANENT`: if true, it will return a 301 status code, otherwise 302
|
||||
- `PRESERVE_PATH`: if true, it will preserve the path of the original request
|
||||
|
||||
### Docker example
|
||||
|
||||
|
|
|
|||
11
src/index.ts
11
src/index.ts
|
|
@ -10,10 +10,19 @@ const app = new Hono();
|
|||
app.get("*", etag(), logger());
|
||||
|
||||
app.get("/", (c) => {
|
||||
const { REDIRECT_URL, PERMANENT } = env(c);
|
||||
const { REDIRECT_URL, PERMANENT, PRESERVE_PATH } = env(c);
|
||||
invariant(REDIRECT_URL, "REDIRECT_URL environment variable is missing");
|
||||
|
||||
const isPermanentRedirect = PERMANENT && PERMANENT === "true";
|
||||
const shouldPreservePath = PRESERVE_PATH && PRESERVE_PATH === "true";
|
||||
|
||||
if (shouldPreservePath) {
|
||||
const path = c.req.path;
|
||||
return c.redirect(
|
||||
`${REDIRECT_URL}${path}`,
|
||||
isPermanentRedirect ? 301 : 302
|
||||
);
|
||||
}
|
||||
|
||||
return c.redirect(REDIRECT_URL, isPermanentRedirect ? 301 : 302);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue