Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<discord token here>
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
Expand All @@ -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)
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
redpin:
container_name: redpin
restart: unless-stopped
env_file: .env
build:
context: .
volumes:
- ./data.db:/data.db
4 changes: 2 additions & 2 deletions src/database/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading