Rewrite run-dev.sh to use golang program
This commit is contained in:
@@ -29,6 +29,18 @@ services:
|
|||||||
- "0.0.0.0:45421:80"
|
- "0.0.0.0:45421:80"
|
||||||
networks:
|
networks:
|
||||||
- cursorius
|
- cursorius
|
||||||
|
gitea:
|
||||||
|
image: gitea/gitea:latest
|
||||||
|
profiles: ["gitea"]
|
||||||
|
environment:
|
||||||
|
- GITEA__webhook__ALLOWED_HOST_LIST=cursorius-server, external
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:2222:22"
|
||||||
|
- "127.0.0.1:3000:3000"
|
||||||
|
networks:
|
||||||
|
- cursorius
|
||||||
|
volumes:
|
||||||
|
- "../_working/gitea:/data"
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
cursorius:
|
cursorius:
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
version: "3.3"
|
|
||||||
services:
|
|
||||||
cursorius-server:
|
|
||||||
networks:
|
|
||||||
- gitea
|
|
||||||
gitea:
|
|
||||||
image: gitea/gitea:latest
|
|
||||||
environment:
|
|
||||||
- GITEA__webhook__ALLOWED_HOST_LIST=cursorius-server, external
|
|
||||||
ports:
|
|
||||||
- "127.0.0.1:2222:22"
|
|
||||||
- "127.0.0.1:3000:3000"
|
|
||||||
networks:
|
|
||||||
- gitea
|
|
||||||
volumes:
|
|
||||||
- gitea-data:/data
|
|
||||||
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
gitea-data:
|
|
||||||
|
|
||||||
networks:
|
|
||||||
gitea:
|
|
||||||
external: false
|
|
||||||
+1
-101
@@ -2,104 +2,4 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
mkdir -p _working/go
|
go run docker/run.go $@
|
||||||
mkdir -p _working/jobs
|
|
||||||
|
|
||||||
base_default_compose_files="docker/docker-compose.yml"
|
|
||||||
default_compose_files="$base_default_compose_files"
|
|
||||||
|
|
||||||
override_compose="docker/docker-compose.override.yml"
|
|
||||||
gitea_compose="docker/gitea-override.yml"
|
|
||||||
|
|
||||||
|
|
||||||
if [ -f "$override_compose" ]
|
|
||||||
then
|
|
||||||
default_compose_files+=" $override_compose"
|
|
||||||
else
|
|
||||||
default_compose_files="docker/docker-compose.yml"
|
|
||||||
fi
|
|
||||||
|
|
||||||
function stop_containers {
|
|
||||||
current_containers="$(cat _working/current_containers)"
|
|
||||||
if [ "$current_containers" == "default" ]
|
|
||||||
then
|
|
||||||
compose_files="$default_compose_files"
|
|
||||||
elif [ "$current_containers" == "gitea" ]
|
|
||||||
then
|
|
||||||
compose_files="$default_compose_files $gitea_compose"
|
|
||||||
fi
|
|
||||||
compose_file_flags=$(echo "$compose_files" | tr ' ' '\n' | xargs -I'{}' echo "-f {} " | tr -d '\n')
|
|
||||||
docker compose $compose_file_flags down
|
|
||||||
}
|
|
||||||
|
|
||||||
function show_logs {
|
|
||||||
current_containers="$(cat _working/current_containers)"
|
|
||||||
if [ "$current_containers" == "default" ]
|
|
||||||
then
|
|
||||||
compose_files="$default_compose_files"
|
|
||||||
elif [ "$current_containers" == "gitea" ]
|
|
||||||
then
|
|
||||||
compose_files="$default_compose_files $gitea_compose"
|
|
||||||
fi
|
|
||||||
compose_file_flags=$(echo "$compose_files" | tr ' ' '\n' | xargs -I'{}' echo "-f {} " | tr -d '\n')
|
|
||||||
docker compose $compose_file_flags logs -f
|
|
||||||
}
|
|
||||||
|
|
||||||
function show_ps {
|
|
||||||
current_containers="$(cat _working/current_containers)"
|
|
||||||
if [ "$current_containers" == "default" ]
|
|
||||||
then
|
|
||||||
compose_files="$default_compose_files"
|
|
||||||
elif [ "$current_containers" == "gitea" ]
|
|
||||||
then
|
|
||||||
compose_files="$default_compose_files $gitea_compose"
|
|
||||||
fi
|
|
||||||
compose_file_flags=$(echo "$compose_files" | tr ' ' '\n' | xargs -I'{}' echo "-f {} " | tr -d '\n')
|
|
||||||
docker compose $compose_file_flags ps
|
|
||||||
}
|
|
||||||
|
|
||||||
function runprev {
|
|
||||||
current_containers="$(cat _working/current_containers)"
|
|
||||||
if [ "$current_containers" == "default" ]
|
|
||||||
then
|
|
||||||
compose_files="$default_compose_files"
|
|
||||||
elif [ "$current_containers" == "gitea" ]
|
|
||||||
then
|
|
||||||
compose_files="$default_compose_files $gitea_compose"
|
|
||||||
fi
|
|
||||||
compose_file_flags=$(echo "$compose_files" | tr ' ' '\n' | xargs -I'{}' echo "-f {} " | tr -d '\n')
|
|
||||||
docker compose $compose_file_flags up --build -d
|
|
||||||
docker compose $compose_file_flags logs -f
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
case $1 in
|
|
||||||
"default")
|
|
||||||
echo "default" > _working/current_containers
|
|
||||||
compose_files="$default_compose_files"
|
|
||||||
compose_file_flags=$(echo "$compose_files" | tr ' ' '\n' | xargs -I'{}' echo "-f {} " | tr -d '\n')
|
|
||||||
docker compose $compose_file_flags up --build -d
|
|
||||||
docker compose $compose_file_flags logs -f;;
|
|
||||||
"gitea")
|
|
||||||
echo "gitea" > _working/current_containers
|
|
||||||
stop_containers
|
|
||||||
compose_files="$default_compose_files $gitea_compose"
|
|
||||||
compose_file_flags=$(echo "$compose_files" | tr ' ' '\n' | xargs -I'{}' echo "-f {} " | tr -d '\n')
|
|
||||||
docker compose $compose_file_flags up --build -d
|
|
||||||
docker compose $compose_file_flags logs -f;;
|
|
||||||
"dbshell")
|
|
||||||
compose_files="$default_compose_files $gitea_compose"
|
|
||||||
compose_file_flags=$(echo "$compose_files" | tr ' ' '\n' | xargs -I'{}' echo "-f {} " | tr -d '\n')
|
|
||||||
docker compose $compose_file_flags exec cursorius-db psql --user=cursorius;;
|
|
||||||
"stop")
|
|
||||||
stop_containers;;
|
|
||||||
"logs")
|
|
||||||
show_logs;;
|
|
||||||
"ps")
|
|
||||||
show_ps;;
|
|
||||||
"runprev")
|
|
||||||
runprev;;
|
|
||||||
*) echo "ERROR: Unknown param \"$1\"" 2>&1
|
|
||||||
exit 255;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func panicError(errorString string, params ...any) {
|
||||||
|
fmt.Fprintf(os.Stderr, fmt.Sprintf("ERROR: %v\n", errorString), params...)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func run(name string, arg ...string) {
|
||||||
|
cmd := exec.Command(name, arg...)
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
panicError("could not run command %v: %v", name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runAttach(name string, arg ...string) {
|
||||||
|
cmd := exec.Command(name, arg...)
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
panicError("could not run command %v: %v", name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runCompose(args []string) {
|
||||||
|
runAttach("docker", append([]string{"compose"}, args...)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createDirs() {
|
||||||
|
run("mkdir", "-p", "_working/go")
|
||||||
|
run("mkdir", "-p", "_working/jobs")
|
||||||
|
}
|
||||||
|
|
||||||
|
func currentContainers() string {
|
||||||
|
bytes, err := os.ReadFile("_working/current_containers")
|
||||||
|
if err != nil {
|
||||||
|
panicError("could not read current containers: %v", err)
|
||||||
|
}
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func composeFlags() []string {
|
||||||
|
containers := currentContainers()
|
||||||
|
flags := []string{"-f", "docker/docker-compose.yml"}
|
||||||
|
switch containers {
|
||||||
|
case "gitea":
|
||||||
|
flags = append(flags, "--profile", "gitea")
|
||||||
|
}
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
func runContainers(containers string) {
|
||||||
|
err := os.WriteFile("_working/current_containers", []byte(containers), 0633)
|
||||||
|
if err != nil {
|
||||||
|
panicError("could not write current_containers file: %v", err)
|
||||||
|
}
|
||||||
|
runCompose(append(composeFlags(), "up", "--build", "-d"))
|
||||||
|
runCompose(append(composeFlags(), "logs", "-f"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) < 2 {
|
||||||
|
panicError("not enough arguments passed")
|
||||||
|
}
|
||||||
|
|
||||||
|
createDirs()
|
||||||
|
|
||||||
|
switch os.Args[1] {
|
||||||
|
case "default", "gitea":
|
||||||
|
runContainers(os.Args[1])
|
||||||
|
case "runprev":
|
||||||
|
runContainers(currentContainers())
|
||||||
|
case "stop":
|
||||||
|
runCompose(append(composeFlags(), "down"))
|
||||||
|
case "dbshell":
|
||||||
|
runCompose(append(composeFlags(), "exec", "cursorius-db", "psql", "--user=cursorius"))
|
||||||
|
case "logs":
|
||||||
|
runCompose(append(composeFlags(), "logs", "-f"))
|
||||||
|
case "ps":
|
||||||
|
runCompose(append(composeFlags(), "ps"))
|
||||||
|
case "help":
|
||||||
|
fmt.Println("commands: default, gitea, runprev, stop, dbshell, logs, ps, help")
|
||||||
|
default:
|
||||||
|
panicError("Unknown subcommand: %v", os.Args[1])
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user