Skip to content

Commit ee970db

Browse files
committed
ADD: initial version, basics working
0 parents  commit ee970db

24 files changed

Lines changed: 588 additions & 0 deletions

.air.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
root = "."
2+
tmp_dir = "tmp"
3+
4+
[build]
5+
bin = "./tmp/main"
6+
cmd = "go build -o ./tmp/main ./cmd/server"
7+
delay = 1000
8+
exclude_dir = ["tmp", "generated"]
9+
exclude_file = []
10+
exclude_regex = []
11+
exclude_unchanged = false
12+
follow_symlink = false
13+
full_bin = ""
14+
include_dir = []
15+
include_ext = ["go", "html", "tmpl"]
16+
kill_delay = "0s"
17+
log = "build-errors.log"
18+
send_interrupt = false
19+
stop_on_error = true
20+
21+
[color]
22+
app = ""
23+
build = "yellow"
24+
main = "magenta"
25+
runner = "green"
26+
watcher = "cyan"
27+
28+
[log]
29+
time = false
30+
31+
[misc]
32+
clean_on_exit = false

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.*
2+
*.env
3+
Dockerfile
4+
*.md
5+
*.sh
6+
tmp

.github/workflows/gcr-deploy.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
workflow_dispatch:
9+
10+
# Environment variables available to all jobs and steps in this workflow
11+
# NOTE: these aren't really secret, but there aren't non-secret settings
12+
env:
13+
RUN_PROJECT: ${{ secrets.RUN_PROJECT }}
14+
RUN_REGION: ${{ secrets.RUN_REGION }}
15+
RUN_SERVICE: ${{ secrets.RUN_SERVICE }}
16+
17+
jobs:
18+
deploy:
19+
name: Deploy to CloudRun
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v1
25+
26+
- name: gcloud auth
27+
id: 'auth'
28+
uses: 'google-github-actions/auth@v0'
29+
with:
30+
credentials_json: '${{ secrets.GCP_SA_KEY }}'
31+
32+
# Setup gcloud CLI
33+
- name: gcloud setup
34+
uses: google-github-actions/setup-gcloud@v0
35+
36+
- name: gcloud docker-auth
37+
run: gcloud auth configure-docker
38+
39+
# Build and push image to Google Container Registry
40+
- name: Build
41+
run: |
42+
docker build \
43+
--build-arg COMMIT=${GITHUB_SHA:0:7} \
44+
--build-arg LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
45+
--tag gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \
46+
.
47+
48+
- name: GCloud auth to docker
49+
run: |
50+
gcloud auth configure-docker
51+
52+
- name: Push to registry
53+
run: |
54+
docker push gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA
55+
56+
# Deploy image to Cloud Run
57+
- name: Deploy
58+
run: |
59+
gcloud run deploy ${RUN_SERVICE} \
60+
--allow-unauthenticated \
61+
--image gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \
62+
--platform managed \
63+
--project ${RUN_PROJECT} \
64+
--region ${RUN_REGION}

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.bundle/
2+
dist/
3+
.DS_Store
4+
*.env
5+
generated/
6+
.jekyll-cache/
7+
.jekyll-metadata
8+
node_modules/
9+
_site/
10+
.sass-cache/
11+
tmp/
12+
*.tmp
13+
vendor/
14+
.wrangler/

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# syntax=docker/dockerfile:1
2+
FROM golang:1.22-alpine AS builder
3+
RUN apk update && \
4+
apk upgrade && \
5+
apk --no-cache add git
6+
RUN mkdir /build
7+
ADD . /build/
8+
WORKDIR /build
9+
ARG COMMIT
10+
ARG LASTMOD
11+
RUN echo "INFO: building for $COMMIT on $LASTMOD"
12+
RUN \
13+
CGO_ENABLED=0 GOOS=linux go build \
14+
-a \
15+
-installsuffix cgo \
16+
-ldflags "-X main.COMMIT=$COMMIT -X main.LASTMOD=$LASTMOD -extldflags '-static'" \
17+
-o svgan-server ./cmd/server
18+
19+
FROM scratch
20+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
21+
COPY --from=builder /build/svgan-server /app/
22+
WORKDIR /app
23+
ENV PORT=4000
24+
ENTRYPOINT ["./svgan-server"]

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SVG Analyzer [<img alt="Logo for SVGan" src="cmd/server/static/favicon.svg" height="96" align="right"/>](https://svgan.fileformat.info/)
2+
3+
Analyze an SVG image
4+
5+
## Credits
6+
7+
[![Bootstrap](https://www.vectorlogo.zone/logos/getbootstrap/getbootstrap-ar21.svg)](https://getbootstrap.com/ "HTML/CSS Framework")
8+
[![Git](https://www.vectorlogo.zone/logos/git-scm/git-scm-ar21.svg)](https://git-scm.com/ "Version control")
9+
[![Github](https://www.vectorlogo.zone/logos/github/github-ar21.svg)](https://github.com/ "Code hosting")
10+
[![Google CloudRun](https://www.vectorlogo.zone/logos/google_cloud_run/google_cloud_run-ar21.svg)](https://cloud.google.com/run/ "Hosting")
11+
[![golang](https://www.vectorlogo.zone/logos/golang/golang-ar21.svg)](https://golang.org/ "Programming language")
12+
[![NodePing](https://www.vectorlogo.zone/logos/nodeping/nodeping-ar21.svg)](https://nodeping.com?rid=201109281250J5K3P "Uptime monitoring")
13+
[![Twitter](https://www.vectorlogo.zone/logos/twitter/twitter-ar21.svg)](https://github.com/twitter/twemoji/blob/gh-pages/v/14.0.2/svg/1f955.svg "Logo")

cmd/.DS_Store

6 KB
Binary file not shown.

cmd/server/.DS_Store

6 KB
Binary file not shown.

cmd/server/assetHandler.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"embed"
5+
"io/fs"
6+
"net/http"
7+
)
8+
9+
//go:embed static
10+
var embeddedFiles embed.FS
11+
var staticHandler = initStaticHandler()
12+
13+
func initStaticHandler() http.Handler {
14+
15+
fsys, err := fs.Sub(embeddedFiles, "static")
16+
if err != nil {
17+
logger.Error("unable to create static file system", "error", err)
18+
panic(err)
19+
}
20+
21+
return http.FileServer(http.FS(fsys))
22+
}

cmd/server/handleJson.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"net/http"
6+
)
7+
8+
func handleJson(w http.ResponseWriter, r *http.Request, data any) {
9+
10+
b, err := json.Marshal(data)
11+
if err != nil {
12+
logger.Error("json.Marshal failed", "error", err, "data", data)
13+
b = []byte("{\"success\":false,\"err\":\"json.Marshal failed\"}")
14+
}
15+
16+
var callback = r.FormValue("callback")
17+
if callback != "" {
18+
w.Header().Set("Content-Type", "application/javascript; charset=utf8")
19+
w.Write([]byte(callback + "("))
20+
w.Write(b)
21+
w.Write([]byte(");"))
22+
} else {
23+
//w.Header().Set("Content-Type", "application/json; charset=utf8")
24+
w.Header().Set("Content-Type", "text/plain; charset=utf8")
25+
w.Header().Set("Access-Control-Allow-Origin", "*")
26+
w.Header().Set("Access-Control-Allow-Methods", "POST, GET")
27+
w.Header().Set("Access-Control-Max-Age", "604800") // 1 week
28+
w.Write(b)
29+
}
30+
}

0 commit comments

Comments
 (0)