init
This commit is contained in:
commit
ed623c3236
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.idea
|
||||||
2
.storage/.gitignore
vendored
Normal file
2
.storage/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
1
application/.gitignore
vendored
Normal file
1
application/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
out.log
|
||||||
3
application/go.mod
Normal file
3
application/go.mod
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module pink_fox
|
||||||
|
|
||||||
|
go 1.24.0
|
||||||
23
application/main.go
Normal file
23
application/main.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
_, _ = fmt.Fprintf(w, "ok")
|
||||||
|
})
|
||||||
|
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
_, _ = fmt.Fprintf(w, "Hello world!")
|
||||||
|
})
|
||||||
|
|
||||||
|
fmt.Println("Starting server at port 12001...")
|
||||||
|
if err := http.ListenAndServe(":12001", nil); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
2
dist/.gitignore
vendored
Normal file
2
dist/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
30
docker-compose.yml
Normal file
30
docker-compose.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
services:
|
||||||
|
|
||||||
|
site:
|
||||||
|
container_name: pink_fox-site
|
||||||
|
build:
|
||||||
|
context: ./services/site
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
ports:
|
||||||
|
- "12001:12001"
|
||||||
|
- "12002:2345"
|
||||||
|
volumes:
|
||||||
|
- ./application:/app
|
||||||
|
- ./dist:/app/dist
|
||||||
|
- ./environment:/var/environment/pink_fox
|
||||||
|
- ./log:/var/log/pink_fox
|
||||||
|
- ./.storage/go:/go
|
||||||
|
environment:
|
||||||
|
- ARG1
|
||||||
|
|
||||||
|
postgres:
|
||||||
|
image: postgres:16
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=pink_fox
|
||||||
|
- POSTGRES_PASSWORD=pink_fox_pass
|
||||||
|
volumes:
|
||||||
|
- ./.storage/postgres:/var/lib/postgresql/data
|
||||||
|
- ./services/postgres/data:/var/backups/postgres
|
||||||
|
- ./services/postgres/init:/docker-entrypoint-initdb.d
|
||||||
|
ports:
|
||||||
|
- "12003:5432"
|
||||||
3
environment/.gitignore
vendored
Normal file
3
environment/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
|
!example.config.yml
|
||||||
0
environment/example.config.yml
Normal file
0
environment/example.config.yml
Normal file
2
log/.gitignore
vendored
Normal file
2
log/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
2
services/postgres/data/.gitignore
vendored
Normal file
2
services/postgres/data/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
1
services/postgres/init/01-databases.sql
Normal file
1
services/postgres/init/01-databases.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
SELECT 'CREATE DATABASE pink_fox_db with owner pink_fox' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'pink_fox_db')\gexec
|
||||||
20
services/site/Dockerfile
Normal file
20
services/site/Dockerfile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
|
RUN apt update && apt upgrade -y
|
||||||
|
RUN apt install -y wget
|
||||||
|
|
||||||
|
ENV PATH=$PATH:/go/go/bin
|
||||||
|
ENV PATH=$PATH:/go/bin
|
||||||
|
ENV GOPATH=/go
|
||||||
|
ENV GOROOT=/go/go
|
||||||
|
ENV GOCACHE=/go/.cache/
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY build.sh /
|
||||||
|
RUN tr -d '\r' < /build.sh > /build.Unix.sh
|
||||||
|
RUN rm /build.sh
|
||||||
|
RUN mv /build.Unix.sh /build.sh
|
||||||
|
RUN chmod +x /build.sh
|
||||||
|
|
||||||
|
CMD [ "/build.sh" ]
|
||||||
42
services/site/build.sh
Executable file
42
services/site/build.sh
Executable file
@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ ! -d "/go/bin" ]]; then
|
||||||
|
# если папка bin не существует устанавливаем в систему go
|
||||||
|
cd /
|
||||||
|
echo "Собираем golang" >> /app/out.log
|
||||||
|
wget https://go.dev/dl/go1.24.0.linux-amd64.tar.gz
|
||||||
|
tar -C /go -xzf go1.24.0.linux-amd64.tar.gz
|
||||||
|
rm -f go1.24.0.linux-amd64.tar.gz
|
||||||
|
|
||||||
|
CGO_ENABLED=0 go install -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@latest
|
||||||
|
|
||||||
|
echo "Golang собран" >> /app/out.log
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$ARG1" = "debug" ]; then
|
||||||
|
# Приложение готовое для дебага
|
||||||
|
cd /app || exit 1
|
||||||
|
rm -f "./dist/local_app_name"
|
||||||
|
echo "" > out.log
|
||||||
|
|
||||||
|
pkill -f /app/dist/local_app_name
|
||||||
|
|
||||||
|
go build -gcflags "all=-N -l" -o ./dist/local_app_name 2> /app/out.log
|
||||||
|
|
||||||
|
if [ ! -s "/app/out.log" ]; then
|
||||||
|
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec /app/dist/local_app_name > /app/out.log 2>&1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Простое приложение
|
||||||
|
cd /app || exit 1
|
||||||
|
rm -f "./dist/local_app_name"
|
||||||
|
echo "" > out.log
|
||||||
|
|
||||||
|
pkill -f /app/dist/local_app_name
|
||||||
|
|
||||||
|
go build -o "./dist/local_app_name" 2> /app/out.log
|
||||||
|
|
||||||
|
if [ ! -s "/app/out.log" ]; then
|
||||||
|
/app/dist/local_app_name > /app/out.log 2>&1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
52
services/site/rerun.py
Executable file
52
services/site/rerun.py
Executable file
@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/python3
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Останавливаем контейнер без задержки
|
||||||
|
subprocess.run(["docker", "compose", "stop", "site", "-t", "0"])
|
||||||
|
|
||||||
|
# Устанавливаем переменные окружения в зависимости от передачи аргумента
|
||||||
|
env = os.environ.copy()
|
||||||
|
if len(sys.argv) > 1 and sys.argv[1] == "debug":
|
||||||
|
env["ARG1"] = "debug"
|
||||||
|
|
||||||
|
# Запускаем сервис через Docker compose
|
||||||
|
subprocess.run(["docker", "compose", "up", "site", "-d", "--build"], env=env)
|
||||||
|
|
||||||
|
attempt_count = 0
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
# Отправляем запрос для проверки поднялся ли HTTP сервер
|
||||||
|
response = requests.get("http://localhost:12001/ping", timeout=5)
|
||||||
|
|
||||||
|
# Проверяем ответ
|
||||||
|
if response.status_code == 200:
|
||||||
|
print("Сервер запущен")
|
||||||
|
break
|
||||||
|
except requests.ConnectionError:
|
||||||
|
try:
|
||||||
|
with open("out.log", 'r') as file:
|
||||||
|
content = file.read().strip()
|
||||||
|
if content:
|
||||||
|
# Лог файл не пуст, возможно, есть ошибки сборки
|
||||||
|
if content.startswith("API server listening at: [::]:2345"):
|
||||||
|
# Лог файл начинается с сообщения о старте дебагера, ошибок нет
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Имеется ошибка компиляции, смотри файл out.log")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Лог файл не найден, проверьте путь")
|
||||||
|
print("Текущая директория" + os.getcwd())
|
||||||
|
|
||||||
|
# Если не удалось подключиться, увеличиваем счетчик попыток
|
||||||
|
attempt_count += 1
|
||||||
|
print(f"Ждем... ({attempt_count})")
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
Loading…
Reference in New Issue
Block a user