-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
263 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "v*.*.*" | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21' | ||
|
||
- name: Build | ||
run: go build -o ./main ./... | ||
- run: mkdir sharedNoteServer; mv main sharedNoteServer/sharedNoteServer; mv run.sh sharedNoteServer/; mv sharedNoteServer.yaml sharedNoteServer/; mv sharednote-cert-issuer.yaml sharedNoteServer/ | ||
- name: Tar | ||
run: tar czf sharedNoteServer.tar.gz sharedNoteServer | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: sharedNoteServer.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
var fileHandler = func(resp http.ResponseWriter, req *http.Request) { | ||
if len(req.Header.Get("X-ENV-WEB")) > 0 && len(req.Header.Get("X-Redirect")) == 0 { | ||
env := req.Header.Get("X-ENV-WEB") | ||
http.FileServer(http.Dir("/root/static/sharedNoteWeb"+env)).ServeHTTP(resp, req) | ||
return | ||
} | ||
http.FileServer(http.Dir(`/root/static/sharedNoteWeb`)).ServeHTTP(resp, req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
var svc = "shared-note-server" | ||
|
||
func forward(resp http.ResponseWriter, req *http.Request) (needForward bool) { | ||
if !(len(req.Header.Get("X-ENV")) > 0 && len(req.Header.Get("X-Redirect")) == 0) { | ||
return false | ||
} | ||
needForward = true | ||
env := req.Header.Get("X-ENV") | ||
url := req.URL | ||
log.Printf("copied url=%+v , %+v, %+v, %+v, %+v, %+v", url, url.Scheme, url.Host, url.Opaque, url.User, url.OmitHost) | ||
url.Scheme = "http" | ||
url.Host = svc + env | ||
|
||
proxyReq, err := http.NewRequest(req.Method, url.String(), req.Body) | ||
if err != nil { | ||
log.Printf("wtf err1=%+v", err) | ||
} | ||
|
||
proxyReq.Header.Set("Host", svc+env) | ||
proxyReq.Header.Set("X-Redirect", "1") | ||
proxyReq.Header.Set("X-Forwarded-For", req.RemoteAddr) | ||
|
||
for header, values := range req.Header { | ||
for _, value := range values { | ||
proxyReq.Header.Add(header, value) | ||
} | ||
} | ||
|
||
client := &http.Client{} | ||
proxyRes, err := client.Do(proxyReq) | ||
if err != nil { | ||
resp.WriteHeader(http.StatusOK) | ||
resp.Write([]byte(err.Error())) | ||
log.Printf("wtf err2=%+v", err) | ||
return | ||
} | ||
resp.WriteHeader(proxyRes.StatusCode) | ||
proxyBody, err := io.ReadAll(proxyRes.Body) | ||
if err != nil { | ||
resp.WriteHeader(http.StatusOK) | ||
resp.Write([]byte(err.Error())) | ||
log.Printf("wtf err3=%+v", err) | ||
return | ||
} | ||
|
||
resp.Write(proxyBody) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
chmod 777 $(dirname -- "$0")/sharedNoteServer | ||
cd $(dirname -- "$0") | ||
./sharedNoteServer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: shared-note-ingress | ||
annotations: | ||
cert-manager.io/issuer: sharednote-issuer | ||
spec: | ||
ingressClassName: "traefik" | ||
tls: | ||
- secretName: sharednote-cert | ||
hosts: | ||
- note.imoonkin.online | ||
rules: | ||
- http: | ||
paths: | ||
- path: / | ||
pathType: Prefix | ||
backend: | ||
service: | ||
name: shared-note-server | ||
port: | ||
number: 12808 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: shared-note-server | ||
spec: | ||
ports: | ||
- port: 12808 | ||
protocol: TCP | ||
selector: | ||
app: shared-note-server | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: shared-note-server | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: shared-note-server | ||
strategy: | ||
type: Recreate | ||
template: | ||
metadata: | ||
labels: | ||
app: shared-note-server | ||
spec: | ||
containers: | ||
- image: imoonkin/goproductpod:latest | ||
name: shared-note-server | ||
ports: | ||
- containerPort: 12808 | ||
name: sharednote-p | ||
volumeMounts: | ||
- name: binaries | ||
mountPath: /root/server | ||
- name: static | ||
mountPath: /root/static | ||
volumes: | ||
- name: binaries | ||
hostPath: | ||
path: /home/product/sharedNoteServer | ||
type: DirectoryOrCreate | ||
- name: static | ||
hostPath: | ||
path: /home/product/static | ||
type: DirectoryOrCreate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: cert-manager.io/v1 | ||
kind: Issuer | ||
metadata: | ||
name: sharednote-issuer | ||
spec: | ||
acme: | ||
server: https://acme-v02.api.letsencrypt.org/directory | ||
email: [email protected] | ||
privateKeySecretRef: | ||
name: acme-account-key | ||
solvers: | ||
- http01: | ||
ingress: | ||
ingressClassName: traefik | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: sharednote-cert | ||
type: kubernetes.io/tls | ||
stringData: | ||
tls.key: "" | ||
tls.crt: "" |