diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2d0e435 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +node_modules/ +.run +.gitignore +config.toml +docker-compose.yml +README.md +bin +config +web/node_modules +web/build \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..778a768 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,44 @@ +name: goreleaser + +on: + push: + tags: + - '*' + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - + name: Set up Node + uses: actions/setup-node@v2 + with: + node-version: '16' + - + name: Build web + run: | + cd web && yarn install + CI= yarn build + - + name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..3532b9a --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,42 @@ +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + goarch: + - amd64 + - arm + - arm64 + goarm: + - 6 + ignore: + - goos: windows + goarch: arm + - goos: windows + goarch: arm64 + main: ./cmd/autobrr/main.go + binary: autobrr + ldflags: + - -s -w + +archives: + - replacements: + amd64: x86_64 + +release: + prerelease: auto + +checksum: + name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt' + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5d2b37b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +# build web +FROM node:16-alpine AS web-builder +WORKDIR /web +COPY web/package.json web/yarn.lock ./ +RUN yarn install --frozen-lockfile +COPY web . +RUN yarn build + +# build app +FROM golang:1.16 AS app-builder + +ENV SERVICE=autobrr + +WORKDIR /src + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . ./ + +COPY --from=web-builder /web/build ./web/build +COPY --from=web-builder /web/build.go ./web + +ENV CGO_ENABLED=0 +ENV GOOS=linux + +#RUN make -f Makefile build/app +RUN go build -o bin/${SERVICE} ./cmd/${SERVICE}/main.go + +# build runner +FROM alpine:latest + +ENV HOME="/config" \ +XDG_CONFIG_HOME="/config" \ +XDG_DATA_HOME="/config" + +RUN apk --no-cache add ca-certificates + +WORKDIR /app + +VOLUME /config + +COPY --from=app-builder /src/bin/autobrr /usr/local/bin/ + +ENTRYPOINT ["autobrr", "--config", "/config"] +#CMD ["--config", "/config"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1b1f842 --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +.PHONY: test +.POSIX: +.SUFFIXES: + +SERVICE = autobrr +GO = go +RM = rm +GOFLAGS = +PREFIX = /usr/local +BINDIR = bin + +all: clean build + +deps: + cd web && yarn install + go mod download + +test: + go test $(go list ./... | grep -v test/integration) + +build: deps build/web build/app + +build/app: + go build -o bin/$(SERVICE) cmd/$(SERVICE)/main.go + +build/web: + cd web && yarn build + +build/docker: + docker build -t autobrr:dev -f Dockerfile . + +clean: + $(RM) -rf bin + +install: all + echo $(DESTDIR)$(PREFIX)/$(BINDIR) + mkdir -p $(DESTDIR)$(PREFIX)/$(BINDIR) + cp -f bin/$(SERVICE) $(DESTDIR)$(PREFIX)/$(BINDIR) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..73a279e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +--- +version: "2.1" +services: + autobrr: + image: autobrr:dev + container_name: autobrr + volumes: + - ./config:/config + ports: + - 8989:8989 + restart: unless-stopped \ No newline at end of file