Skip to content

Commit c999bd4

Browse files
committed
Initial Commit
0 parents  commit c999bd4

File tree

10 files changed

+2732
-0
lines changed

10 files changed

+2732
-0
lines changed

.air.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
root = "."
2+
testdata_dir = "testdata"
3+
tmp_dir = "tmp"
4+
5+
[build]
6+
args_bin = []
7+
bin = "./tmp/main"
8+
cmd = "go build -o ./tmp/main ."
9+
delay = 1000
10+
exclude_dir = ["assets", "tmp", "vendor", "testdata", "uploads"]
11+
exclude_file = []
12+
exclude_regex = ["_test.go"]
13+
exclude_unchanged = false
14+
follow_symlink = false
15+
full_bin = ""
16+
include_dir = []
17+
include_ext = ["go", "tpl", "tmpl", "html"]
18+
include_file = []
19+
kill_delay = "0s"
20+
log = "build-errors.log"
21+
poll = false
22+
poll_interval = 0
23+
rerun = false
24+
rerun_delay = 500
25+
send_interrupt = false
26+
stop_on_root = false
27+
28+
[color]
29+
app = ""
30+
build = "yellow"
31+
main = "magenta"
32+
runner = "green"
33+
watcher = "cyan"
34+
35+
[log]
36+
main_only = false
37+
time = false
38+
39+
[misc]
40+
clean_on_exit = false
41+
42+
[screen]
43+
clear_on_rebuild = false
44+
keep_scroll = true

.github/workflows/ci.yml

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
release:
9+
types: [ published ]
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
go-version: [1.21, 1.22]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v4
23+
with:
24+
go-version: ${{ matrix.go-version }}
25+
26+
- name: Cache Go modules
27+
uses: actions/cache@v3
28+
with:
29+
path: ~/go/pkg/mod
30+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
31+
restore-keys: |
32+
${{ runner.os }}-go-
33+
34+
- name: Install dependencies
35+
run: go mod download
36+
37+
- name: Verify dependencies
38+
run: go mod verify
39+
40+
- name: Run tests
41+
run: go test -v -race -coverprofile=coverage.out ./...
42+
43+
- name: Upload coverage to Codecov
44+
uses: codecov/codecov-action@v3
45+
with:
46+
file: ./coverage.out
47+
48+
- name: Run go vet
49+
run: go vet ./...
50+
51+
- name: Run staticcheck
52+
uses: dominikh/staticcheck-action@v1.3.0
53+
with:
54+
version: "2023.1.6"
55+
56+
build:
57+
needs: test
58+
runs-on: ubuntu-latest
59+
strategy:
60+
matrix:
61+
os: [linux, windows, darwin]
62+
arch: [amd64, arm64]
63+
exclude:
64+
- os: windows
65+
arch: arm64
66+
67+
steps:
68+
- uses: actions/checkout@v4
69+
70+
- name: Set up Go
71+
uses: actions/setup-go@v4
72+
with:
73+
go-version: 1.21
74+
75+
- name: Cache Go modules
76+
uses: actions/cache@v3
77+
with:
78+
path: ~/go/pkg/mod
79+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
80+
restore-keys: |
81+
${{ runner.os }}-go-
82+
83+
- name: Install dependencies
84+
run: go mod download
85+
86+
- name: Build server
87+
run: |
88+
CGO_ENABLED=1 GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -o server-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.os == 'windows' && '.exe' || '' }} .
89+
90+
- name: Build CLI
91+
run: |
92+
CGO_ENABLED=1 GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -o uploader-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.os == 'windows' && '.exe' || '' }} ./cmd/cli
93+
94+
- name: Upload artifacts
95+
uses: actions/upload-artifact@v3
96+
with:
97+
name: binaries-${{ matrix.os }}-${{ matrix.arch }}
98+
path: |
99+
server-${{ matrix.os }}-${{ matrix.arch }}*
100+
uploader-${{ matrix.os }}-${{ matrix.arch }}*
101+
102+
docker:
103+
needs: test
104+
runs-on: ubuntu-latest
105+
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
106+
107+
steps:
108+
- uses: actions/checkout@v4
109+
110+
- name: Set up Docker Buildx
111+
uses: docker/setup-buildx-action@v3
112+
113+
- name: Login to Docker Hub
114+
uses: docker/login-action@v3
115+
with:
116+
username: ${{ secrets.DOCKERHUB_USERNAME }}
117+
password: ${{ secrets.DOCKERHUB_TOKEN }}
118+
119+
- name: Extract metadata
120+
id: meta
121+
uses: docker/metadata-action@v5
122+
with:
123+
images: ${{ secrets.DOCKERHUB_USERNAME }}/fileuploader
124+
tags: |
125+
type=ref,event=branch
126+
type=ref,event=pr
127+
type=semver,pattern={{version}}
128+
type=semver,pattern={{major}}.{{minor}}
129+
type=raw,value=latest,enable={{is_default_branch}}
130+
131+
- name: Build and push
132+
uses: docker/build-push-action@v5
133+
with:
134+
context: .
135+
push: true
136+
tags: ${{ steps.meta.outputs.tags }}
137+
labels: ${{ steps.meta.outputs.labels }}
138+
cache-from: type=gha
139+
cache-to: type=gha,mode=max
140+
platforms: linux/amd64,linux/arm64
141+
142+
release:
143+
needs: [test, build]
144+
runs-on: ubuntu-latest
145+
if: github.event_name == 'release'
146+
147+
steps:
148+
- uses: actions/checkout@v4
149+
150+
- name: Download all artifacts
151+
uses: actions/download-artifact@v3
152+
153+
- name: Create release package
154+
run: |
155+
mkdir -p release
156+
for dir in binaries-*/; do
157+
cp -r "$dir"* release/
158+
done
159+
cp README.md docker-compose.yml Dockerfile release/
160+
cd release
161+
tar -czf ../fileuploader-${{ github.event.release.tag_name }}.tar.gz .
162+
cd ..
163+
164+
- name: Upload release assets
165+
uses: actions/upload-release-asset@v1
166+
env:
167+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
168+
with:
169+
upload_url: ${{ github.event.release.upload_url }}
170+
asset_path: ./fileuploader-${{ github.event.release.tag_name }}.tar.gz
171+
asset_name: fileuploader-${{ github.event.release.tag_name }}.tar.gz
172+
asset_content_type: application/gzip
173+
174+
- name: Upload individual binaries
175+
run: |
176+
for file in release/server-* release/uploader-*; do
177+
if [ -f "$file" ]; then
178+
filename=$(basename "$file")
179+
curl \
180+
-X POST \
181+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
182+
-H "Content-Type: application/octet-stream" \
183+
--data-binary @"$file" \
184+
"${{ github.event.release.upload_url }}?name=$filename"
185+
fi
186+
done

.gitignore

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
server
8+
uploader
9+
server-*
10+
uploader-*
11+
12+
# Test binary, built with `go test -c`
13+
*.test
14+
15+
# Output of the go coverage tool, specifically when used with LiteIDE
16+
*.out
17+
coverage.html
18+
19+
# Dependency directories (remove the comment below to include it)
20+
# vendor/
21+
22+
# Go workspace file
23+
go.work
24+
25+
# IDE files
26+
.vscode/
27+
.idea/
28+
*.swp
29+
*.swo
30+
*~
31+
32+
# OS generated files
33+
.DS_Store
34+
.DS_Store?
35+
._*
36+
.Spotlight-V100
37+
.Trashes
38+
ehthumbs.db
39+
Thumbs.db
40+
41+
# Database files
42+
*.db
43+
*.db-journal
44+
*.db-shm
45+
*.db-wal
46+
*.sqlite
47+
*.sqlite3
48+
fileuploader.db*
49+
50+
# Upload directory
51+
uploads/
52+
tmp/
53+
54+
# Log files
55+
*.log
56+
build-errors.log
57+
58+
# Air (development) files
59+
tmp/
60+
.air.toml.local
61+
62+
# Docker volumes
63+
docker-data/
64+
65+
# Release directory
66+
release/
67+
68+
# Backup files
69+
*.backup
70+
*.bak
71+
72+
# Environment files
73+
.env
74+
.env.local
75+
.env.production
76+
77+
# Test files
78+
test.txt
79+
testfile.*
80+
81+
# Node modules (if you add any frontend dependencies)
82+
node_modules/
83+
84+
# Certificate files
85+
*.pem
86+
*.key
87+
*.crt
88+
*.cer

Dockerfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Build stage
2+
FROM golang:1.21-alpine AS builder
3+
4+
# Install git for go mod download
5+
RUN apk add --no-cache git
6+
7+
# Set working directory
8+
WORKDIR /app
9+
10+
# Copy go mod files
11+
COPY go.mod go.sum ./
12+
13+
# Download dependencies
14+
RUN go mod download
15+
16+
# Copy source code
17+
COPY . .
18+
19+
# Build the server
20+
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o server .
21+
22+
# Build the CLI
23+
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o uploader ./cmd/cli
24+
25+
# Runtime stage
26+
FROM alpine:latest
27+
28+
# Install ca-certificates and sqlite
29+
RUN apk --no-cache add ca-certificates sqlite
30+
31+
# Create non-root user
32+
RUN adduser -D -s /bin/sh appuser
33+
34+
# Set working directory
35+
WORKDIR /app
36+
37+
# Copy binaries from builder
38+
COPY --from=builder /app/server .
39+
COPY --from=builder /app/uploader .
40+
41+
# Create uploads directory
42+
RUN mkdir -p uploads && chown appuser:appuser uploads
43+
44+
# Change ownership of app directory
45+
RUN chown -R appuser:appuser /app
46+
47+
# Switch to non-root user
48+
USER appuser
49+
50+
# Expose port
51+
EXPOSE 3000
52+
53+
# Health check
54+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
55+
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
56+
57+
# Set environment variables
58+
ENV PORT=3000
59+
ENV GIN_MODE=release
60+
# ENV API_KEY=your_secret_api_key_here
61+
62+
# Run the server
63+
CMD ["./server"]

0 commit comments

Comments
 (0)