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
21 changes: 14 additions & 7 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@ jobs:
run: |
go test ./...

- name: Build
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs=false -o main
code_quality:
name: Code Quality🎖️
runs-on: ubuntu-latest
container: "golangci/golangci-lint:v1.62.2"
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Get dependencies
run: go get -v -t -d ./...
- name: GolangCI-Lint
run: |
golangci-lint run --timeout 9m0s

release_package:
if: ${{ startsWith(github.ref, 'refs/tags/v')}}
needs: [test_and_build,code_quality]
runs-on: ubuntu-latest

permissions:
Expand All @@ -48,10 +59,6 @@ jobs:
run: |
go mod download

- name: Build
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs=false -o main

- name: Extract Release Tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

Expand All @@ -68,4 +75,4 @@ jobs:
push: true
context: .
file: Dockerfile
tags: zopdev/static-server:${{ env.RELEASE_VERSION }}, zopdev/static-server:latest
tags: zopdev/static-server:${{ env.RELEASE_VERSION }}
15 changes: 13 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Build stage
FROM golang:1.22 AS build

WORKDIR /src
COPY . .
RUN go get ./...
RUN go build -ldflags "-linkmode external -extldflags -static" -a -o /app/main main.go

# Final stage
FROM alpine:3.14
RUN apk add --no-cache tzdata ca-certificates

COPY main main
COPY configs configs
COPY --from=build /app/main /main
COPY --from=build /src/configs /configs

CMD ["/main"]
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Static Server

A simple and efficient solution for serving static files.

## Features

- **Easy to use**: Just place your static files in the `static` directory, and the server takes care of the rest.
- **Dockerized**: Easily deployable as a Docker container.
- **Lightweight**: Minimal dependencies for optimal performance.
- **Configurable**: You can easily configure the server or extend it based on your needs.
- The server serves files from the `static` directory by default, but you can change this by setting the `STATIC_DIR_PATH` environment variable.
- Support all the confgs of the gofr framework - https://gofr.dev

## Usage

### 1. Build a Docker image

To deploy the server, you need to build a Docker image using the provided `Dockerfile`.

#### Example `Dockerfile`

```dockerfile
# Use the official static-server image as the base image
# This will pull the latest prebuilt version of the static-server to run your static website
FROM zopdev/static-server:latest

# Copy static files into the container
# The 'COPY' directive moves your static files (in this case, located at '/app/out') into the '/website' directory
# which is where the static server expects to find the files to serve
COPY /app/out /static

# Expose the port on which the server will run
# By default, the server listens on port 8000, so we expose that port to allow access from outside the container
EXPOSE 8000

# Define the command to run the server
# The static server is started with the '/main' binary included in the image, which will start serving
# the files from the '/website' directory on port 8000
CMD ["/main"]
```

### 2. Build the Docker image

Navigate to your project directory and run the following command to build the Docker image:

```bash
docker build -t static-server .
```

This command:
- Uses the `Dockerfile` in the current directory (`.`) to build an image.
- Tags the image with the name `static-server` (`-t static-server`).

### 3. Run the Docker container

Once the image is built, run the container using the following command:

```bash
docker run -d -p 8000:8000 static-server
```

This command:
- Runs the container in detached mode (`-d`).
- Maps port 8000 on your host machine to port 8000 inside the container (`-p 8000:8000`), so you can access the static files via `http://localhost:8000`.

### 4. Access your static website

Once the container is running, you can visit your website at:

```
http://localhost:8000
```

Your static files will be served, and the root (`/`) will typically display your `index.html` (if present).

## Notes

- The server serves all files in the `website` directory, so make sure to avoid any sensitive files or configuration details in that directory.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
3 changes: 1 addition & 2 deletions configs/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
APP_NAME=static-server

HTTP_PORT=8000
STATIC_DIR_PATH=
60 changes: 30 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module zop.dev/static-server

go 1.22.9

require gofr.dev v1.27.1
require gofr.dev v1.28.2

require (
cloud.google.com/go v0.116.0 // indirect
cloud.google.com/go/auth v0.9.9 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
cloud.google.com/go/auth v0.11.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
cloud.google.com/go/compute/metadata v0.5.2 // indirect
cloud.google.com/go/iam v1.2.1 // indirect
cloud.google.com/go/pubsub v1.45.1 // indirect
cloud.google.com/go/iam v1.2.2 // indirect
cloud.google.com/go/pubsub v1.45.3 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
Expand All @@ -31,11 +31,11 @@ require (
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/klauspost/compress v1.17.9 // indirect
Expand All @@ -56,42 +56,42 @@ require (
github.com/redis/go-redis/v9 v9.7.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/segmentio/kafka-go v0.4.47 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/stretchr/testify v1.10.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.31.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.52.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.32.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/mock v0.5.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.7.0 // indirect
google.golang.org/api v0.203.0 // indirect
google.golang.org/genproto v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/api v0.210.0 // indirect
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241113202542-65e8d215514f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/grpc v1.68.1 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
modernc.org/libc v1.55.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/sqlite v1.33.1 // indirect
modernc.org/sqlite v1.34.2 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect
)
Loading
Loading