diff --git a/.dockerignore b/.dockerignore index 885eac2..65eef93 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1 @@ db -templates diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..66cb630 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,36 @@ +name: Docker Build and Publish + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build-and-publish: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile-optimized + push: ${{ github.event_name != 'pull_request' }} + tags: | + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:${{ github.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.gitignore b/.gitignore index 6f4c7e1..76ec0b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ db/ .env -wot-relay \ No newline at end of file diff --git a/Dockerfile-optimized b/Dockerfile-optimized new file mode 100644 index 0000000..2c80ed9 --- /dev/null +++ b/Dockerfile-optimized @@ -0,0 +1,44 @@ +# Stage 1: Build the Go application +FROM golang:bookworm AS builder + +# Set the working directory within the container +WORKDIR /app + +# Copy go.mod and go.sum files +COPY go.mod go.sum ./ + +# Download dependencies +RUN go mod download + +# Copy the rest of the application source code +COPY . . + +# Set fixed environment variables for build +ENV DB_PATH="db" +ENV INDEX_PATH="templates/index.html" +ENV STATIC_PATH="templates/static" + +# touch a .env +RUN touch .env + +# Build the Go application +RUN go build -o main . + +# Stage 2: Create a minimal image to run the Go application +FROM debian:bookworm-slim + +# Set the working directory within the container +WORKDIR /app + +# Copy the Go binary from the builder stage +COPY --from=builder /app/main /app/ + +# Copy any necessary files like templates, static assets, etc. +COPY --from=builder /app/templates /app/templates +COPY --from=builder /app/.env /app/ + +# Expose the port that the application will run on +EXPOSE 3334 + +# Set the command to run the executable +CMD ["./main"] diff --git a/main.go b/main.go index f418641..59a629b 100644 --- a/main.go +++ b/main.go @@ -46,17 +46,17 @@ func main() { reset := "\033[0m" art := ` -888 888 88888888888 8888888b. 888 -888 o 888 888 888 Y88b 888 -888 d8b 888 888 888 888 888 -888 d888b 888 .d88b. 888 888 d88P .d88b. 888 8888b. 888 888 -888d88888b888 d88""88b 888 8888888P" d8P Y8b 888 "88b 888 888 -88888P Y88888 888 888 888 888 T88b 88888888 888 .d888888 888 888 -8888P Y8888 Y88..88P 888 888 T88b Y8b. 888 888 888 Y88b 888 -888P Y888 "Y88P" 888 888 T88b "Y8888 888 "Y888888 "Y88888 - 888 - Y8b d88P - powered by: khatru "Y88P" +888 888 88888888888 8888888b. 888 +888 o 888 888 888 Y88b 888 +888 d8b 888 888 888 888 888 +888 d888b 888 .d88b. 888 888 d88P .d88b. 888 8888b. 888 888 +888d88888b888 d88""88b 888 8888888P" d8P Y8b 888 "88b 888 888 +88888P Y88888 888 888 888 888 T88b 88888888 888 .d888888 888 888 +8888P Y8888 Y88..88P 888 888 T88b Y8b. 888 888 888 Y88b 888 +888P Y888 "Y88P" 888 888 T88b "Y8888 888 "Y888888 "Y88888 + 888 + Y8b d88P + powered by: khatru "Y88P" ` fmt.Println(green + art + reset)