This commit is contained in:
parent
85584447fc
commit
08794960bf
|
@ -0,0 +1,96 @@
|
||||||
|
name: Build
|
||||||
|
|
||||||
|
# Controls when the workflow will run
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'main'
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'main'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
# Get the repository's code
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
-
|
||||||
|
# https://github.com/vegardit/docker-gitea-act-runner/issues/23
|
||||||
|
name: Fix docker sock permissions
|
||||||
|
run: sudo chmod 666 /var/run/docker.sock
|
||||||
|
-
|
||||||
|
# https://github.com/docker/setup-qemu-action
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
-
|
||||||
|
# https://github.com/docker/setup-buildx-action
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
-
|
||||||
|
# https://github.com/docker/login-action
|
||||||
|
name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
# Maybe there is a default env var for this?
|
||||||
|
registry: git.maronato.dev
|
||||||
|
username: ${{ github.repository_owner }}}
|
||||||
|
# Ideally, we should only need to set "permissions: package: write", but
|
||||||
|
# Gitea is having issues with that. For now, this is a manually created
|
||||||
|
# token available user-wise, with the "package:write" permission.
|
||||||
|
password: ${{ secrets.PACKAGE_WRITE_TOKEN }}
|
||||||
|
-
|
||||||
|
# https://github.com/docker/metadata-action
|
||||||
|
# Generate tags and labels for the image
|
||||||
|
# according to the commit and the branch
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v4
|
||||||
|
with:
|
||||||
|
# The container image name needs the custom registry in it.
|
||||||
|
# Maybe there is a default env var for this?
|
||||||
|
images: git.maronato.dev/${{ github.repository }}
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=ref,event=pr
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
-
|
||||||
|
# httos://github.com/actions/cache
|
||||||
|
name: Configure cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
/go/pkg/mod/
|
||||||
|
/tmp/.npm-cache
|
||||||
|
/tmp/.go-build-cache
|
||||||
|
/tmp/.buildx-cache
|
||||||
|
key: ${{ runner.os }}-build-
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-build-
|
||||||
|
-
|
||||||
|
# https://github.com/docker/build-push-action
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=local,src=/tmp/.buildx-cache
|
||||||
|
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
|
||||||
|
# cache-to: type=local,dest=/tmp/.build-cache/buildx-new,mode=max
|
||||||
|
# -
|
||||||
|
# # "Temp" fix
|
||||||
|
# # https://github.com/docker/build-push-action/issues/252
|
||||||
|
# # https://github.com/moby/buildkit/issues/1896
|
||||||
|
# name: Move cache
|
||||||
|
# run: |
|
||||||
|
# rm -rf /tmp/.build-cache/buildx
|
||||||
|
# mv /tmp/.build-cache/buildx-new /tmp/.build-cache/buildx
|
58
Dockerfile
58
Dockerfile
|
@ -0,0 +1,58 @@
|
||||||
|
# Load the golang image
|
||||||
|
FROM golang:1.20.7 as go-builder
|
||||||
|
# Then the node image
|
||||||
|
FROM node:20.5.0 as builder
|
||||||
|
|
||||||
|
# Copy golang into the node image
|
||||||
|
COPY --from=go-builder /usr/local/go /usr/local/go
|
||||||
|
|
||||||
|
# Now our base image is ready.
|
||||||
|
|
||||||
|
# Continue as normal
|
||||||
|
WORKDIR /go/src/app
|
||||||
|
|
||||||
|
# Set our build environment
|
||||||
|
ENV GOPATH=/go
|
||||||
|
ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
|
||||||
|
ENV GOCACHE=/tmp/.go-build-cache
|
||||||
|
ENV CGO_ENABLED=0
|
||||||
|
# This variable communicates to the service that it's running inside
|
||||||
|
# a docker container.
|
||||||
|
ENV ENV_DOCKER=true
|
||||||
|
|
||||||
|
# Copy dockerignore files
|
||||||
|
COPY .dockerignore ./
|
||||||
|
|
||||||
|
# Install go deps using the cache
|
||||||
|
COPY go.mod go.sum Makefile ./
|
||||||
|
RUN --mount=type=cache,target=/go/pkg/mod/ \
|
||||||
|
go mod download -x
|
||||||
|
|
||||||
|
# Install node deps
|
||||||
|
COPY frontend/package.json frontend/package-lock.json frontend/
|
||||||
|
# Set npm cache to /tmp/.npm-cache
|
||||||
|
RUN npm config set cache /tmp/.npm-cache --global
|
||||||
|
RUN --mount=type=cache,target=/tmp/.npm-cache \
|
||||||
|
make install
|
||||||
|
|
||||||
|
# Build the frontend
|
||||||
|
COPY frontend frontend
|
||||||
|
RUN make frontend
|
||||||
|
|
||||||
|
# Build the backend
|
||||||
|
COPY . .
|
||||||
|
RUN --mount=type=cache,target=/tmp/.go-build-cache \
|
||||||
|
make backend
|
||||||
|
|
||||||
|
# Now create a new image with just the binary
|
||||||
|
FROM gcr.io/distroless/static-debian11:nonroot
|
||||||
|
|
||||||
|
# Set our runtime environment
|
||||||
|
ENV ENV_DOCKER=true
|
||||||
|
|
||||||
|
COPY --from=builder /go/src/app/goshort /usr/local/bin/goshort
|
||||||
|
|
||||||
|
HEALTHCHECK CMD [ "goshort", "healthcheck" ]
|
||||||
|
|
||||||
|
ENTRYPOINT [ "goshort" ]
|
||||||
|
CMD [ "serve" ]
|
|
@ -12,7 +12,7 @@ import ItemBase from "./ItemBase"
|
||||||
|
|
||||||
const ShortItem: FunctionComponent<Short> = ({ ...short }) => {
|
const ShortItem: FunctionComponent<Short> = ({ ...short }) => {
|
||||||
const origin = location.origin
|
const origin = location.origin
|
||||||
const host = "marona.to"
|
const host = location.host
|
||||||
|
|
||||||
const maxSize = 120
|
const maxSize = 120
|
||||||
const displayURL =
|
const displayURL =
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -5,6 +5,7 @@ go 1.20
|
||||||
require (
|
require (
|
||||||
github.com/alexedwards/scs/v2 v2.5.1
|
github.com/alexedwards/scs/v2 v2.5.1
|
||||||
github.com/go-chi/chi/v5 v5.0.10
|
github.com/go-chi/chi/v5 v5.0.10
|
||||||
|
github.com/go-chi/cors v1.2.1
|
||||||
github.com/go-chi/render v1.0.3
|
github.com/go-chi/render v1.0.3
|
||||||
github.com/peterbourgon/ff/v3 v3.4.0
|
github.com/peterbourgon/ff/v3 v3.4.0
|
||||||
golang.org/x/crypto v0.12.0
|
golang.org/x/crypto v0.12.0
|
||||||
|
@ -13,6 +14,5 @@ require (
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ajg/form v1.5.1 // indirect
|
github.com/ajg/form v1.5.1 // indirect
|
||||||
github.com/go-chi/cors v1.2.1 // indirect
|
|
||||||
golang.org/x/sys v0.11.0 // indirect
|
golang.org/x/sys v0.11.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user