diff --git a/.gitea/workflows/build_to_registry.yaml b/.gitea/workflows/build_to_registry.yaml new file mode 100644 index 0000000..4da1d05 --- /dev/null +++ b/.gitea/workflows/build_to_registry.yaml @@ -0,0 +1,45 @@ +name: Build and Push to GHCR + +on: + push: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 'stable' + + - name: Run tests + run: go test -v ./... + + - name: Build + run: go build -o app ./cmd/app + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: git.gocommunity.ru + username: ${{ secrets.USER }} + password: ${{ secrets.TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + git.gocommunity.ru/${{ github.repository }}:latest + git.gocommunity.ru/${{ github.repository }}:${{ github.sha }} + labels: | + org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} \ No newline at end of file diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/old/build.yaml similarity index 100% rename from .gitea/workflows/build.yaml rename to .gitea/workflows/old/build.yaml diff --git a/cmd/app.go b/cmd/app.go new file mode 100644 index 0000000..d8edafb --- /dev/null +++ b/cmd/app.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "os" + "time" +) + +func main() { + http.HandleFunc("/", helloHandler) + http.HandleFunc("/health", healthHandler) + + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + + log.Printf("Server starting on port %s", port) + log.Fatal(http.ListenAndServe(":"+port, nil)) +} + +func helloHandler(w http.ResponseWriter, r *http.Request) { + name := r.URL.Query().Get("name") + if name == "" { + name = "World" + } + fmt.Fprintf(w, "Hello %s!\n", name) +} + +func healthHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + fmt.Fprintf(w, `{"status": "healthy", "timestamp": "%s"}`, time.Now().Format(time.RFC3339)) +}