diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..44b0a35 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM golang:latest AS builder + +# Set build directory +WORKDIR /build + +# Copy Go dependency files +COPY src/go.* . + +# Download and verify Go modules +RUN go mod download +RUN go mod verify + +# Copy the rest of the source code +COPY src/ . + +# Build app +RUN CGO_ENABLED=0 GOOS=linux go build -v -o redpin + + + +FROM scratch + +# Copy necessary files from builder +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /build/redpin . + +# Run redpin +CMD ["./redpin"] diff --git a/README.md b/README.md index 26f29b7..fe179c3 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,27 @@ TODO This repository contains the modern rewrite and expansion of **redpin** in the Go. If you are looking for the original Python version, see [redpin-py](https://github.com/jadc/redpin-py); I rewrote this bot to practice interfacing with databases and APIs, routing packets, responding to asynchronous events, and generally extend the features of this bot significantly past its current form and existing (free and paid) offerings. +## Installation +The recommended way of hosting is using [Docker](https://www.docker.com/). +1. Clone this repository. + + ```sh + git clone https://github.com/jadc/redpin.git + ``` +2. Create an environment file named `.env` with the following contents. + + ``` + DISCORD_TOKEN= + DB_FILE=[optional, path to database file] + ``` +3. Run the container using Docker Compose. + + ```sh + docker compose up + ``` + +Of course, you can host it without Docker. If you want to do it that way, you probably know how. :) + ## TODO - [x] Implement core functionality @@ -29,6 +50,6 @@ This repository contains the modern rewrite and expansion of **redpin** in the G - [x] Leaderboard for users with most pins (and emojis used) - [ ] Write tests - [x] Write CI/CD pipeline for automatic building and running tests -- [ ] Write Dockerfile for production deployment +- [x] Write Dockerfile for production deployment - [x] Write Nix Shell for development environment - [ ] Showcase bot in [Tour](#Tour) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..32b5653 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + redpin: + container_name: redpin + restart: unless-stopped + env_file: .env + build: + context: . + volumes: + - ./data.db:/data.db diff --git a/src/database/main.go b/src/database/main.go index d2bd5b5..48168ec 100644 --- a/src/database/main.go +++ b/src/database/main.go @@ -25,8 +25,8 @@ func Connect() (*database, error) { once.Do(func(){ // Retrieve file name from the environment database_url := "data.db" - if x := os.Getenv("SQLITE_FILE_NAME"); x != "" { - log.Println("Using environmental variable 'SQLITE_FILE_NAME' for database name.") + if x := os.Getenv("DB_FILE"); x != "" { + log.Println("Using environmental variable 'DB_FILE' for database name.") database_url = x }