From 4e06ababf358811d70c8f381af6e58ebdf8e8b8b Mon Sep 17 00:00:00 2001 From: Konstantin Grachev Date: Fri, 18 Jul 2025 22:20:49 +0300 Subject: [PATCH] init --- .gitea/workflows/build.yaml | 47 +++++++++++++++++++++++++++++++++++++ Dockerfile | 7 ++++++ go.mod | 3 +++ main.go | 27 +++++++++++++++++++++ public/.gitkeep | 0 5 files changed, 84 insertions(+) create mode 100644 .gitea/workflows/build.yaml create mode 100644 Dockerfile create mode 100644 go.mod create mode 100644 main.go create mode 100644 public/.gitkeep diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..6a5923f --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,47 @@ +name: Build and Push + +on: + push: + branches: + - main # Триггер на пуш в ветку main + tags: + - 'v*' # Триггер на теги, начинающиеся с 'v' + +env: + HARBOR_REGISTRY: harbor.grachevko.ru # Адрес вашего Harbor + HARBOR_PROJECT: obsidian # Название проекта в Harbor + IMAGE_NAME: server # Название образа + DOCKERFILE_PATH: ./Dockerfile # Путь к Dockerfile + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Login to Harbor + uses: docker/login-action@v3 + with: + registry: ${{ env.HARBOR_REGISTRY }} + username: ${{ secrets.HARBOR_USERNAME }} + password: ${{ secrets.HARBOR_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.HARBOR_REGISTRY }}/${{ env.HARBOR_PROJECT }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=sha + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ${{ env.DOCKERFILE_PATH }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..39468dd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM golang:1.24.5-alpine + +ENV CGO_ENABLED=0 + +WORKDIR /usr/src/app + +COPY . . diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e29de1d --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module server + +go 1.24.5 diff --git a/main.go b/main.go new file mode 100644 index 0000000..d2e99c4 --- /dev/null +++ b/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "embed" + "io/fs" + "log" + "net/http" +) + +//go:embed public/* +var publicFS embed.FS + +func main() { + // Получаем подпапку 'public' из embed.FS + pub, err := fs.Sub(publicFS, "public") + if err != nil { + log.Fatal(err) + } + + // Создаем файловый сервер с корнем в подпапке public + fileServer := http.FileServer(http.FS(pub)) + + http.Handle("/", fileServer) + + log.Println("Server starting on :8080") + log.Fatal(http.ListenAndServe(":8080", nil)) +} diff --git a/public/.gitkeep b/public/.gitkeep new file mode 100644 index 0000000..e69de29