Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
luisguillenc committed Oct 24, 2019
0 parents commit cab2fd3
Show file tree
Hide file tree
Showing 301 changed files with 23,794 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM golang:alpine as build-env
ARG arch=amd64

# Install git and certificates
RUN apk update && apk add --no-cache git make ca-certificates && update-ca-certificates

# create user for service
RUN adduser -D -g '' xlist

WORKDIR /app
## dependences
COPY go.mod .
COPY go.sum .
RUN go mod download

## build
COPY . .
RUN make binaries SYSTEM="GOOS=linux GOARCH=${arch}"

## create docker
FROM scratch

LABEL maintainer="Luis Guillén Civera <luisguillenc@gmail.com>"

# Import the user and group files from the builder.
COPY --from=build-env /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build-env /etc/passwd /etc/passwd

COPY --from=build-env /app/bin/xlistc /bin/
COPY --from=build-env /app/bin/xlistd /bin/
COPY --from=build-env /app/configs/docker/* /etc/xlist/

USER xlist

EXPOSE 5801
VOLUME [ "/etc/xlist", "/var/lib/xlist" ]
CMD [ "/bin/xlistd" ]
36 changes: 36 additions & 0 deletions Dockerfile.xlget
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM golang:alpine as build-env
ARG arch=amd64

# Install git and certificates
RUN apk update && apk add --no-cache git make ca-certificates && update-ca-certificates

WORKDIR /app
## dependences
COPY go.mod .
COPY go.sum .
RUN go mod download

## build
COPY . .
RUN make binaries SYSTEM="GOOS=linux GOARCH=${arch}"

## create docker
FROM alpine

LABEL maintainer="Luis Guillén Civera <luisguillenc@gmail.com>"

RUN apk update && apk add --no-cache ca-certificates && update-ca-certificates

# create user for service
RUN adduser -D -g '' xlist && \
mkdir -p /var/lib/xlist && \
chown xlist /var/lib/xlist

COPY --from=build-env /app/bin/xlget /bin/
COPY --from=build-env /app/configs/empty.json /etc/xlist/sources.d/

USER xlist

VOLUME [ "/etc/xlist/sources.d", "/var/lib/xlist" ]

CMD [ "/bin/xlget", "--auto", "-S", "/etc/xlist/sources.d", "--xlget.output", "/var/lib/xlist", "--xlget.cache", "/var/lib/xlist/.cache" ]
662 changes: 662 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Makefile for building xlist

# Project binaries
COMMANDS=xlistd xlistc xlget
BINARIES=$(addprefix bin/,$(COMMANDS))

# Used to populate version in binaries
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
DATEBUILD=$(shell date +%FT%T%z)

# Compilation opts
GOPATH?=$(HOME)/go
SYSTEM:=
CGO_ENABLED:=0
BUILDOPTS:=-v
BUILDLDFLAGS=-ldflags '-s -w -X main.Version=$(VERSION) -X main.Revision=$(REVISION) -X main.Build=$(DATEBUILD) $(EXTRA_LDFLAGS)'

# Print output
WHALE = "+"

.PHONY: all binaries clean
all: binaries


FORCE:


# Build a binary from a cmd.
bin/%: cmd/% FORCE
@echo "$(WHALE) $@${BINARY_SUFFIX}"
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) $(SYSTEM) \
go build $(BUILDOPTS) -o $@${BINARY_SUFFIX} ${BUILDLDFLAGS} ./$<


binaries: $(BINARIES)
@echo "$(WHALE) $@"


clean:
@echo "$(WHALE) $@"
@rm -f $(BINARIES)
@rmdir bin

## Targets for Makefile.release
.PHONY: release
release:
@$(if $(value BINARY),, $(error Undefined BINARY))
@$(if $(value COMMAND),, $(error Undefined COMMAND))
@echo "$(WHALE) $@"
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) $(SYSTEM) \
go build $(BUILDOPTS) ${BUILDLDFLAGS} -o $(BINARY) ./cmd/$(COMMAND)

# tests
.PHONY: test test-core test-plugin
test: test-core test-plugin
@echo "$(WHALE) $@"


test-core:
@echo "$(WHALE) $@"
( cd pkg/builder ; GO111MODULE=on go test -v -race ./...)


test-plugin:
@echo "$(WHALE) $@"
( cd pkg/components ; GO111MODULE=on go test -v -race ./... )
( cd pkg/wrappers ; GO111MODULE=on go test -v -race ./... )

72 changes: 72 additions & 0 deletions Makefile.release
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Makefile for release xlist

EMPTY:=
SPACE:=$(EMPTY) $(EMPTY)
COMMA:=$(EMPTY),$(EMPTY)

ifeq (, $(shell which curl))
$(error "No curl in $$PATH, please install")
endif


NAME:=luxlist
COMMANDS=xlistd xlistc xlget
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
LINUX_ARCH:=amd64 arm arm64 ppc64le s390x
PLATFORMS:=$(subst $(SPACE),$(COMMA),$(foreach arch,$(LINUX_ARCH),linux/$(arch)))

all:
@echo Use the 'release' target to build a release.

release: build tar

.PHONY: build
build:
@echo Cleaning old builds
@rm -rf build && mkdir build
@echo Building: darwin/amd64 - $(VERSION)
mkdir -p build/darwin/amd64
for cmd in $(COMMANDS); do \
$(MAKE) release COMMAND=$$cmd BINARY=build/darwin/amd64/$${cmd} \
SYSTEM="GOOS=darwin GOARCH=amd64" CHECKS="" BUILDOPTS="" ;\
done
@echo Building: windows/amd64 - $(VERSION)
mkdir -p build/windows/amd64
for cmd in $(COMMANDS); do \
$(MAKE) release COMMAND=$$cmd BINARY=build/windows/amd64/$${cmd}.exe \
SYSTEM="GOOS=windows GOARCH=amd64" CHECKS="" BUILDOPTS="" ;\
done
@echo Building: linux/mips - $(VERSION)
mkdir -p build/linux/mips
for cmd in $(COMMANDS); do \
$(MAKE) release COMMAND=$$cmd BINARY=build/linux/mips/$${cmd} \
SYSTEM="GOOS=linux GOARCH=mips" CHECKS="" BUILDOPTS="" ;\
done
@echo Building: linux/$(LINUX_ARCH) - $(VERSION) ;\
for arch in $(LINUX_ARCH); do \
mkdir -p build/linux/$$arch ; \
for cmd in $(COMMANDS); do \
$(MAKE) release COMMAND=$$cmd BINARY=build/linux/$${arch}/$${cmd} \
SYSTEM="GOOS=linux GOARCH=$$arch" CHECKS="" BUILDOPTS="" ;\
done ; \
done

.PHONY: tar
tar:
@echo Cleaning old releases
@rm -rf release && mkdir release
tar -zcf release/$(NAME)_$(VERSION)_darwin_amd64.tgz -C build/darwin/amd64 .
tar -zcf release/$(NAME)_$(VERSION)_windows_amd64.tgz -C build/windows/amd64 .
tar -zcf release/$(NAME)_$(VERSION)_linux_mips.tgz -C build/linux/mips .
for arch in $(LINUX_ARCH); do \
tar -zcf release/$(NAME)_$(VERSION)_linux_$$arch.tgz -C build/linux/$$arch . ;\
done

.PHONY: version
version:
@echo $(VERSION)

.PHONY: clean
clean:
rm -rf release
rm -rf build
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# xlist

Coming soon...
32 changes: 32 additions & 0 deletions cmd/xlget/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2019 Luis Guillén Civera <luisguillenc@gmail.com>. View LICENSE.

package config

import (
cconfig "github.com/luids-io/common/config"
iconfig "github.com/luids-io/xlist/internal/config"
"github.com/luisguillenc/goconfig"
)

// Default returns the default configuration
func Default(program string) *goconfig.Config {
cfg, err := goconfig.New(program,
goconfig.Section{
Name: "xlget",
Required: true,
Short: true,
Data: &iconfig.XLGetCfg{},
},
goconfig.Section{
Name: "log",
Required: true,
Data: &cconfig.LoggerCfg{
Level: "info",
},
},
)
if err != nil {
panic(err)
}
return cfg
}
23 changes: 23 additions & 0 deletions cmd/xlget/depend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2019 Luis Guillén Civera <luisguillenc@gmail.com>. View LICENSE.

package main

import (
"github.com/luisguillenc/yalogi"

cconfig "github.com/luids-io/common/config"
cfactory "github.com/luids-io/common/factory"
iconfig "github.com/luids-io/xlist/internal/config"
ifactory "github.com/luids-io/xlist/internal/factory"
"github.com/luids-io/xlist/pkg/xlget"
)

func createLogger(debug bool) (yalogi.Logger, error) {
cfgLog := cfg.Data("log").(*cconfig.LoggerCfg)
return cfactory.Logger(cfgLog, debug)
}

func createManager(logger yalogi.Logger) (*xlget.Manager, error) {
cfgGet := cfg.Data("xlget").(*iconfig.XLGetCfg)
return ifactory.XLGet(cfgGet, logger)
}
Loading

0 comments on commit cab2fd3

Please sign in to comment.