feat: add docker installation/setup

This commit is contained in:
Lucas Barbieri 2024-08-19 15:50:17 -03:00
parent cd467d26d0
commit 7bd098e589
4 changed files with 48 additions and 7 deletions

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM golang:1.23
WORKDIR /app
# COPY go.mod go.sum ./
COPY go.mod ./
RUN go mod download
COPY *.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -o /abyss
CMD ["/abyss"]

View File

@ -3,12 +3,27 @@ abyss is a basic http server made for uploading files (logs, images) and then sh
note: this is a project made for learning purposes, you should use other more mature projects if running in production
## running:
- edit consts in `main.go` to match your needs. (for example, on server, change `$url` so that the response will be nicely formatted)
## table of contents
- [running abyss](#running)
- [installing with docker](#docker)
- [installing manually](#manual)
- [todo list](#todo)
- to run it, either build with `go build -o abyss && ./abyss` or run it directly with:
## running:
- change URL env variable in to your domain. example: `URL=paste.abyss.dev`
### docker
- to run with docker, you can use either docker compose or just straight docker.
- then run the docker compose command:
```bash
go run ./main.go
docker compose up -d # might be docker-compose depending on distro
```
- dont change inside port of 8080 unless you know what you're doing
### manual
- to run it, either build with `go build -o abyss` or run it directly with:
```bash
URL="your-domain" go run ./main.go
```
- then, simply upload your files with curl:
@ -17,6 +32,6 @@ curl -X POST -F "file=@/path/to/file" http://localhost:8080/upload # default url
```
## todo:
- [x] add upload of logs funcionality (like 0x0.st)
- [ ] add docker easy setup
- [x] add docker easy setup
- [ ] add db for tracking of file names
- [ ] add file browser (like file://)

7
docker-compose.yml Normal file
View File

@ -0,0 +1,7 @@
services:
paste:
environment:
URL: "localhost:58080"
build: .
ports:
- "58080:8080"

View File

@ -10,11 +10,12 @@ import (
)
const (
url = "localhost"
port = ":8080"
filesDir = "./files"
)
var url string = os.Getenv("URL")
func main() {
http.HandleFunc("/upload", uploadHandler)
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(filesDir))))
@ -54,5 +55,9 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Error copying the file", http.StatusInternalServerError)
}
fmt.Fprintf(w, "http://%s%s/%d\n", url, port, time)
if url == "" {
fmt.Fprintf(w, "http://localhost%s/%d\n", port, time)
} else {
fmt.Fprintf(w, "http://%s/%d\n", url, time)
}
}