If you’re having this issue with building
https://gitlab.com/mattwb65/srt-live-server.git
Continue reading “Compiling gitlab.com/mattwb65/srt-live-server error solution”
How to package your SPA or PWA without a Dockerfile using Go and ko
Writing Dockerfiles is a pain in the ass.
All you want to do is publish your SPA or PWA dist files in a docker container and maybe even push it to a private registry.
Instead of having to write a Dockerfile, pull some base OS, increase the size of the container image, add potential attack surfaces / vulnerabilities coming from those base OS images, you can wrap and embed it in a Go binary.
Install ko
Create a ko-build.sh in the project root
1 2 3 |
#!/bin/bash ko login registry.domain.tld -u myuser -p mypassword KO_DOCKER_REPO=registry.domain.tld/user/my-frontend ko build --platform=all |
1 2 |
go mod init git.domain.tld/user/repo touch main.go |
and edit main.go and insert the following
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
package main import ( "embed" "io/fs" "log" "net/http" "strings" ) //go:embed dist var pwa embed.FS //go:embed dist/index.html var index embed.FS var indexFile []byte func init() { var e error indexFile, e = index.ReadFile("dist/index.html") if e != nil { log.Fatal(e.Error()) } } func main() { root, e := fs.Sub(pwa, "dist") if e != nil { log.Fatal(e.Error()) } log.Fatal(http.ListenAndServe(":8080", Handler(root))) } func Handler(root fs.FS) http.Handler { handler := http.FileServer(http.FS(root)) return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { _path := req.URL.Path // static files if strings.Contains(_path, ".") || _path == "/" { handler.ServeHTTP(w, req) return } w.Write(indexFile) }) } |
assuming your bundler, e.g. vite, places dist files in your project root’s dist
dir (vite default),
1 2 3 4 5 6 |
dist ├── assets │  ├── index-D-1oofZ3.css │  └── index-DMGf-fk6.js ├── index.html └── vite.svg |
If your dist files are in dist/pwa
and your index file is at dist/pwa/index.html
edit the lines accordingly.
This is effectively what would be in nginx:
1 2 3 |
location / { try_files $uri $uri/ /index.html; } |
Your container exposes port 8080
Build and publish
1 |
bash ko-build.sh |
Since you only need to write this once, you can copy the main.go to every project that requires it and adjust the ko-build.sh script.
Yes, this survives CTRL+F5 reloads. It routes everything through index.html unless it’s a static file that exists on the filesystem.
k8s delete pv or pvc first?
Banned from entgo, why?
I wanted to create an issue, in github.com/ent/ent the size annotation doesn’t have any effect when used on a MySQL database.
I couldn’t create the issue, “unable to create issue”, and no further information.
So I said that I can’t create an issue in their discord.
Then I wrote, “So I’ve been banned. What for? Being to critical of Atlas?”
Without any response I was banned from the discord as well.
?!?
Because I don’t agree with giving them my schema information when I need to use it in a k8s context?
I don’t know because I never received a reason.
Seriously, I’ve had enough of those emotionally and mentally unstable mini dictators, banning people for personal entertainment or satisfying their inferiority complex.
Absolutely unacceptable behavior banning someone from their discord only for asking what’s wrong.
Ariel Mashraki need his head examined.
Update 21. Jan. 2025:
I created an issue with Atlas where I demanded the ban lifted or my contributions, issues, discussions and comments deleted.
That issue was deleted and I was banned from the Atlas repository.
I’m now going to file copyright and intellectural property violations with Github, also find a lawyer to sue them.
Looking back
Looking back, I feel the current point in time is like the beginning of a new chapter.
I was very hurt and angry since my Ex cheated on me in 2010 and that created a lot of pain and unusual behavior which lead to mostly bad things happening in my life.
I’m not saying everything is different, but things have changed.
I feel like I’m slowly getting my inner balance back.