build: releases with actions and docker

This commit is contained in:
Ludvig Lundgren 2021-08-11 15:41:09 +02:00
parent 773e57afe6
commit 2e8d0950c1
6 changed files with 191 additions and 0 deletions

10
.dockerignore Normal file
View file

@ -0,0 +1,10 @@
node_modules/
.run
.gitignore
config.toml
docker-compose.yml
README.md
bin
config
web/node_modules
web/build

44
.github/workflows/release.yml vendored Normal file
View file

@ -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 }}

42
.goreleaser.yml Normal file
View file

@ -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:'

46
Dockerfile Normal file
View file

@ -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"]

38
Makefile Normal file
View file

@ -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)

11
docker-compose.yml Normal file
View file

@ -0,0 +1,11 @@
---
version: "2.1"
services:
autobrr:
image: autobrr:dev
container_name: autobrr
volumes:
- ./config:/config
ports:
- 8989:8989
restart: unless-stopped