init
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
aovantsev
2025-10-02 22:30:16 +03:00
parent fba4bb58f9
commit 0dcb5d9b87
7 changed files with 159 additions and 2 deletions

41
.drone.yml Normal file
View File

@@ -0,0 +1,41 @@
kind: pipeline
type: docker
name: default
steps:
- name: build-and-deploy
image: docker:20.10.16
environment:
DOCKER_HOST: unix:///var/run/docker.sock
volumes:
- name: docker-sock
path: /var/run/docker.sock
commands:
# Build the Docker image
- docker build -t localhost:5000/counter:latest .
# Push to local registry
- docker push localhost:5000/counter:latest
# Stop and remove existing container if it exists
- docker stop counter-app || true
- docker rm counter-app || true
# Run the new container
- docker run -d --name counter-app -p 8080:8080 localhost:5000/counter:latest
# Wait a moment for the container to start
- sleep 5
# Test the API
- curl -f http://localhost:8080/ || exit 1
volumes:
- name: docker-sock
host:
path: /var/run/docker.sock
trigger:
branch:
- main
- master

33
.gitignore vendored Normal file
View File

@@ -0,0 +1,33 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
# IDE files
.vscode/
.idea/
*.swp
*.swo
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

33
Dockerfile Normal file
View File

@@ -0,0 +1,33 @@
# Build stage
FROM golang:1.21-alpine AS builder
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
# Final stage
FROM alpine:latest
# Install ca-certificates for HTTPS requests
RUN apk --no-cache add ca-certificates
WORKDIR /root/
# Copy the binary from builder stage
COPY --from=builder /app/main .
# Expose port
EXPOSE 8080
# Run the binary
CMD ["./main"]

View File

@@ -1,2 +0,0 @@
# counter

24
docker-compose.yml Normal file
View File

@@ -0,0 +1,24 @@
version: '3.8'
services:
# Local Docker Registry for testing
registry:
image: registry:2
ports:
- "5000:5000"
volumes:
- registry-data:/var/lib/registry
environment:
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /var/lib/registry
# The counter application
counter-app:
build: .
ports:
- "8080:8080"
depends_on:
- registry
image: localhost:5000/counter:latest
volumes:
registry-data:

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module counter
go 1.21

25
main.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import (
"log"
"net/http"
)
func helloHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write([]byte("Hello world"))
}
func main() {
http.HandleFunc("/", helloHandler)
port := ":8080"
log.Printf("Server starting on port %s", port)
log.Fatal(http.ListenAndServe(port, nil))
}