forked from toolshed/coop-cloud-backend
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cd45bcf5c5 | |||
| 8423cf5f69 | |||
| 62be5ddda7 | |||
| 3a88c8d878 | |||
| 25d01298e5 | |||
| fd53e28143 | |||
| c5e773a694 | |||
| cd47863622 | |||
| 3775894a5b |
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "web"]
|
||||||
|
path = web
|
||||||
|
url = ssh://git@git.coopcloud.tech:2222/toolshed/coop-cloud-front.git
|
||||||
33
Dockerfile
33
Dockerfile
@ -1,15 +1,30 @@
|
|||||||
FROM golang:1.25
|
FROM golang:1.25
|
||||||
RUN mkdir /backend
|
RUN mkdir /backend
|
||||||
COPY . /backend/
|
COPY --parents ["api", "cli", "internal", "go.mod", "go.sum", "app.go", "/backend/"]
|
||||||
RUN go build -C /backend -o app
|
RUN go build -C /backend -o gobackend
|
||||||
EXPOSE 3000
|
|
||||||
|
|
||||||
FROM node
|
FROM node
|
||||||
RUN mkdir /frontend
|
RUN mkdir /home/node/wizard
|
||||||
WORKDIR /frontend
|
COPY --from=0 /backend/gobackend /home/node/wizard/gobackend
|
||||||
RUN git clone https://git.coopcloud.tech/BornDeleuze/coop-cloud-front
|
|
||||||
EXPOSE 5173
|
COPY --parents web /home/node/wizard
|
||||||
|
WORKDIR /home/node/wizard/web
|
||||||
|
RUN npm install .
|
||||||
|
|
||||||
|
USER node
|
||||||
|
RUN curl https://install.abra.coopcloud.tech | bash
|
||||||
|
ENV ABRA_BIN=/home/node/.local/bin/abra
|
||||||
|
RUN $ABRA_BIN recipe fetch -a
|
||||||
|
|
||||||
COPY ./start.sh /
|
COPY ./start.sh /
|
||||||
COPY --from=0 /backend/app /backend/app
|
COPY dot_abra /home/node/.abra/
|
||||||
ENTRYPOINT [ "/start.sh" ]
|
COPY ssh_config /home/node/.ssh/config
|
||||||
|
COPY id_ed25519_* /home/node/.ssh/
|
||||||
|
|
||||||
|
USER root
|
||||||
|
RUN chown -R node /home/node/
|
||||||
|
USER node
|
||||||
|
|
||||||
|
EXPOSE 5173 3000
|
||||||
|
# ENV VITE_API_URL=http://localhost:3000/api
|
||||||
|
CMD [ "/start.sh" ]
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
A Go service that exposes RESTful API endpoints to manage Abra programmatically.
|
A Go service that exposes RESTful API endpoints to manage Abra programmatically.
|
||||||
Integrates with https://git.coopcloud.tech/BornDeleuze/coop-cloud-front.
|
Integrates with https://git.coopcloud.tech/BornDeleuze/coop-cloud-front.
|
||||||
|
|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
- Edit the front-end application to turn off mock mode in `src/routes/Authenticated/App.tsx` and `src/routes/Authenticated/Apps.tsx`.
|
- Edit the front-end application to turn off mock mode in `src/routes/Authenticated/App.tsx` and `src/routes/Authenticated/Apps.tsx`.
|
||||||
|
|||||||
24
api/api.go
24
api/api.go
@ -1,9 +1,11 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"encoding/json"
|
|
||||||
"coopcloud.tech/abra/pkg/client"
|
"coopcloud.tech/abra/pkg/client"
|
||||||
"coopcloud.tech/abra/pkg/upstream/stack"
|
"coopcloud.tech/abra/pkg/upstream/stack"
|
||||||
|
|
||||||
@ -11,19 +13,22 @@ import (
|
|||||||
configPkg "coopcloud.tech/abra/pkg/config"
|
configPkg "coopcloud.tech/abra/pkg/config"
|
||||||
deployPkg "coopcloud.tech/abra/pkg/deploy"
|
deployPkg "coopcloud.tech/abra/pkg/deploy"
|
||||||
|
|
||||||
composetypes "github.com/docker/cli/cli/compose/types"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
composetypes "github.com/docker/cli/cli/compose/types"
|
||||||
|
|
||||||
"coop-cloud-backend/internal"
|
"coop-cloud-backend/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
type abraHandler struct {
|
type abraHandler struct {
|
||||||
mux *http.ServeMux
|
mux *http.ServeMux
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAbraHandler() *abraHandler {
|
func newAbraHandler() *abraHandler {
|
||||||
h := &abraHandler{
|
h := &abraHandler{
|
||||||
mux: http.NewServeMux(),
|
mux: http.NewServeMux(),
|
||||||
}
|
}
|
||||||
h.mux.HandleFunc("/apps", func(w http.ResponseWriter, r *http.Request) {
|
h.mux.HandleFunc("/api/abra/apps", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||||
@ -38,7 +43,7 @@ func newAbraHandler() *abraHandler {
|
|||||||
http.Error(w, "Method not implemented", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not implemented", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
h.mux.HandleFunc("/apps/{serverId}/{appId}/deploy", func(w http.ResponseWriter, r *http.Request) {
|
h.mux.HandleFunc("/api/abra/apps/{serverId}/{appId}/deploy", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
|
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||||
@ -54,7 +59,7 @@ func newAbraHandler() *abraHandler {
|
|||||||
http.Error(w, "Method not implemented", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not implemented", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
h.mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
|
h.mux.HandleFunc("/api/abra/servers", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||||
@ -73,8 +78,8 @@ func newAbraHandler() *abraHandler {
|
|||||||
}
|
}
|
||||||
func StartAPI() {
|
func StartAPI() {
|
||||||
h := newAbraHandler()
|
h := newAbraHandler()
|
||||||
fmt.Println("Server started on port 3000")
|
log.Println("Server started on port 3000")
|
||||||
http.ListenAndServe(":3000", h)
|
log.Fatal(http.ListenAndServe(":3000", h))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *abraHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *abraHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -84,6 +89,7 @@ func (h *abraHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Delegate to internal mux
|
// Delegate to internal mux
|
||||||
h.mux.ServeHTTP(w, r)
|
h.mux.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (h *appHandler) handleStartApp(w http.ResponseWriter, r *http.Request) {
|
// func (h *appHandler) handleStartApp(w http.ResponseWriter, r *http.Request) {
|
||||||
// appName := r.PathValue("appName")
|
// appName := r.PathValue("appName")
|
||||||
// w.Write([]byte("starting app: " + appName))
|
// w.Write([]byte("starting app: " + appName))
|
||||||
@ -111,7 +117,7 @@ func (h *abraHandler) handleDeployApp(w http.ResponseWriter, r *http.Request, ap
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if deployMeta.IsDeployed {
|
if deployMeta.IsDeployed {
|
||||||
log.Fatal("%s is already deployed", app.Name)
|
log.Fatalf("%s is already deployed", app.Name)
|
||||||
InternalServerErrorHandler(w, r)
|
InternalServerErrorHandler(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -295,7 +301,7 @@ func (h *abraHandler) handleListApps(w http.ResponseWriter, r *http.Request) {
|
|||||||
appStatuses, err := GetAppStatuses(remoteApps)
|
appStatuses, err := GetAppStatuses(remoteApps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("GetAppStatuses Falied\n")
|
log.Printf("GetAppStatuses Falied\n")
|
||||||
fmt.Println("Error: ", err)
|
log.Println("Error: ", err)
|
||||||
InternalServerErrorHandler(w, r)
|
InternalServerErrorHandler(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
8
app.go
8
app.go
@ -49,7 +49,7 @@ import (
|
|||||||
// return envMap, nil
|
// return envMap, nil
|
||||||
// }
|
// }
|
||||||
func printApp(app appPkg.App) error {
|
func printApp(app appPkg.App) error {
|
||||||
fmt.Printf("Name: %s | Domain: %s | Server: %s | Path: %s",
|
log.Printf("Name: %s | Domain: %s | Server: %s | Path: %s",
|
||||||
app.Name, app.Domain, app.Server, app.Path)
|
app.Name, app.Domain, app.Server, app.Path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -64,13 +64,13 @@ func connectToContainer(app appPkg.App, serviceName string) {
|
|||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
filters.Add("name", stackAndServiceName)
|
filters.Add("name", stackAndServiceName)
|
||||||
|
|
||||||
fmt.Printf("HI?")
|
log.Printf("HI?")
|
||||||
|
|
||||||
targetContainer, err := containerPkg.GetContainer(context.Background(), cl, filters, false)
|
targetContainer, err := containerPkg.GetContainer(context.Background(), cl, filters, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Container ID: %s", targetContainer.ID)
|
log.Printf("Container ID: %s", targetContainer.ID)
|
||||||
}
|
}
|
||||||
func main() {
|
func main() {
|
||||||
appNames, err := appPkg.GetAppNames()
|
appNames, err := appPkg.GetAppNames()
|
||||||
@ -79,7 +79,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
for _, appName := range appNames {
|
for _, appName := range appNames {
|
||||||
val := fmt.Sprintf("app , %v", appName)
|
val := fmt.Sprintf("app , %v", appName)
|
||||||
fmt.Println(val)
|
log.Println(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
api.StartAPI()
|
api.StartAPI()
|
||||||
|
|||||||
5
start.sh
5
start.sh
@ -1,6 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
/backend/app &
|
/home/node/wizard/gobackend &
|
||||||
|
|
||||||
cd /frontend
|
npm run dev -- --host
|
||||||
npm run dev
|
|
||||||
|
|||||||
1
web
Submodule
1
web
Submodule
Submodule web added at 08510b136e
Reference in New Issue
Block a user