Skip to content

Commit

Permalink
Updated Dockerfile
Browse files Browse the repository at this point in the history
- Created Makefile
- Updated readme
  • Loading branch information
0xNoNames committed Nov 16, 2024
1 parent 0720e99 commit 9515cab
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ go.work.sum
# env file
.env

dist/
downloads/
torrents/
*.torrent
25 changes: 14 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
FROM golang:1.23.3 as builder

# Build binary
FROM --platform=$BUILDPLATFORM golang:1.23.3-alpine AS build-env
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
# Copy the go sources
COPY . .

# Build
# RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o ghostbox GhostBox.go
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o ghostbox GhostBox.go
ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -ldflags="-s -w" -o ghostbox GhostBox.go

RUN mkdir torrents downloads


# Create image
# Use distroless as minimal base image to package the manager binary
FROM alpine:latest
# Create the /torrents and /downloads directories
FROM scratch
WORKDIR /app
RUN mkdir torrents downloads
COPY --from=builder /workspace/ghostbox .
COPY --from=build-env /workspace/ghostbox .
COPY --from=build-env /workspace/torrents .
COPY --from=build-env /workspace/downloads .
CMD [ "/app/ghostbox", "-i", "/app/torrents", "-o", "/app/downloads" ]
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.DEFAULT_GOAL := default

IMAGE ?= xnonames/ghostbox:latest

export DOCKER_CLI_EXPERIMENTAL=enabled

.PHONY: build # Build the container image
build:
@docker buildx create --use --name=crossplat --node=crossplat && \
docker buildx build \
--output "type=docker,push=false" \
--tag $(IMAGE) \
.

.PHONY: publish # Push the image to the remote registry
publish:
@docker buildx create --use --name=crossplat --node=crossplat && \
docker buildx build \
--platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm/v8,linux/arm64,linux/ppc64le,linux/s390x \
--output "type=image,push=true" \
--tag $(IMAGE) \
.


.PHONY: generate
generate:
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags="-s -w" -o dist/ghostbox_linux_i386 GhostBox.go # Linux 32bit
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o dist/ghostbox_linux_x86_64 GhostBox.go # Linux 64bit
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags="-s -w" -o dist/ghostbox_linux_arm GhostBox.go # Linux armv5/armel/arm (it also works on armv6)
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-s -w" -o dist/ghostbox_linux_armhf GhostBox.go # Linux armv7/armhf
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o dist/ghostbox_linux_aarch64 GhostBox.go # Linux armv8/aarch64
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w" -o dist/ghostbox_freebsd_x86_64 GhostBox.go # FreeBSD 64bit
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o dist/ghostbox_darwin_x86_64 GhostBox.go # Darwin 64bit
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o dist/ghostbox_darwin_aarch64 GhostBox.go # Darwin armv8/aarch64
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="-s -w" -o dist/ghostbox_windows_i386.exe GhostBox.go # Windows 32bit
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o dist/ghostbox_windows_x86_64.exe GhostBox.go # Windows 64bit
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ docker run --rm \
-e PGID=501 \
-v ./downloads:/app/downloads \
-v ./torrents:/app/torrents \
ghostbox:latest
xnonames/ghostbox:latest
```

### Docker Compose
Expand All @@ -54,7 +54,7 @@ docker run --rm \
---
services:
ghostbox:
image: ghostbox:latest
image: xnonames/ghostbox:latest
container_name: ghostbox
environment:
- PUID=501
Expand Down

0 comments on commit 9515cab

Please sign in to comment.