Skip to content

Commit

Permalink
Merge pull request #4 from pollystack/docker-compose-changes
Browse files Browse the repository at this point in the history
Adding docker compose changes
  • Loading branch information
allnash authored Oct 28, 2024
2 parents 0e02b27 + 5190360 commit 01e7b58
Show file tree
Hide file tree
Showing 32 changed files with 390 additions and 154 deletions.
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Host Directory Paths
CONFIG_PATH=./config.yaml
SSL_PATH=./ssl
WWW_PATH=./www
LOG_PATH=./logs

# Server Ports
HTTP_PORT=80
HTTPS_PORT=443
15 changes: 9 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ FROM golang:1.21-alpine as builder
# Set the working directory inside the container
WORKDIR /app

# Copy the entire project
COPY fast-server .
# Copy go.mod and go.sum first (from fast-server directory)
COPY fast-server/go.mod fast-server/go.sum ./

# Download all dependencies (this will create go.sum if it doesn't exist)
# Download dependencies
RUN go mod download

# Copy the entire fast-server directory
COPY fast-server/ .

# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o fast_server .

Expand All @@ -19,12 +22,12 @@ FROM alpine:latest
# Install ca-certificates
RUN apk --no-cache add ca-certificates

WORKDIR /root/
WORKDIR /app

# Copy the pre-built binary file from the previous stage
# Copy the pre-built binary
COPY --from=builder /app/fast_server .

# Copy the config file
# Copy the config file from root directory
COPY config.yaml.example /etc/fast/config.yaml

# Create necessary directories
Expand Down
48 changes: 27 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ INSTALL_DIR=/usr/local/bin
CONFIG_DIR=/etc/fast
LOG_DIR=/var/log/fast
WWW_DIR=/var/www/fast
DOCKER_IMAGE_NAME=fast-server
CODE_DIR=fast-server
DOCKER_CONTAINER_NAME=fast-server-container

.PHONY: all linux darwin windows clean install uninstall docker-build docker-run docker-stop
.PHONY: all linux darwin windows clean install uninstall docker-compose-up docker-compose-down docker-compose-build docker-compose-logs

all: linux darwin windows

Expand All @@ -30,6 +28,7 @@ windows:
@cd $(CODE_DIR) && go get -d -v && \
mkdir -p $(BUILD_DIR) && \
GOOS=windows go build -o $(BUILD_DIR)/$(BINARY_NAME)-windows.exe main.go

clean:
@echo "Cleaning..."
@rm -rf $(BUILD_DIR)
Expand Down Expand Up @@ -59,23 +58,30 @@ uninstall:
@sudo systemctl daemon-reload
@echo "FAST server uninstalled"

docker-build:
@echo "Building Docker image..."
docker build -t $(DOCKER_IMAGE_NAME) .
# Docker Compose commands
docker-compose-build:
@echo "Building with Docker Compose..."
docker-compose build

docker-compose-up:
@echo "Starting with Docker Compose..."
docker-compose up -d

docker-compose-down:
@echo "Stopping with Docker Compose..."
docker-compose down

docker-run:
@echo "Running Docker container..."
docker run -d \
-p 80:80 \
-p 443:443 \
-v $(WWW_DIR):/var/www/fast \
-v $(CONFIG_DIR)/ssl:/etc/fast/ssl \
-v $(LOG_DIR):/var/log/fast \
-v $(CONFIG_DIR)/config.yaml:/etc/fast/config.yaml \
--name $(DOCKER_CONTAINER_NAME) \
$(DOCKER_IMAGE_NAME)
docker-compose-logs:
@echo "Viewing Docker Compose logs..."
docker-compose logs -f

docker-stop:
@echo "Stopping Docker container..."
docker stop $(DOCKER_CONTAINER_NAME)
docker rm $(DOCKER_CONTAINER_NAME)
# Initialize development environment
init-dev:
@echo "Initializing development environment..."
@cp config.yaml.example config.yaml
@cp .env.example .env
@mkdir -p ssl/domain1.lan ssl/domain2.lan ssl/global www logs
@echo "Generating test certificates..."
@openssl req -x509 -newkey rsa:4096 -keyout ssl/domain1.lan/privkey.pem -out ssl/domain1.lan/fullchain.pem -days 365 -nodes -subj "/CN=domain1.lan"
@openssl req -x509 -newkey rsa:4096 -keyout ssl/domain2.lan/privkey.pem -out ssl/domain2.lan/fullchain.pem -days 365 -nodes -subj "/CN=domain2.lan"
@openssl req -x509 -newkey rsa:4096 -keyout ssl/global/privkey.pem -out ssl/global/fullchain.pem -days 365 -nodes -subj "/CN=localhost"
Loading

0 comments on commit 01e7b58

Please sign in to comment.