diff --git a/.gitignore b/.gitignore index ce730a3..86736ee 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ config.yml data it/*.db cmd/migrations + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..72ec670 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,107 @@ +before: + hooks: + - go mod download + - go generate ./cmd + +builds: + - id: ot-recorder + flags: + - -tags=osusergo,netgo,sqlite_omit_load_extension + ldflags: + - -extldflags=-static + - -s -w + - -X ot-recorder/app.Version={{.Version}} + - -X ot-recorder/app.BuildTime={{.Date}} + env: + - CGO_ENABLED=1 + goos: + - linux + goarch: + - amd64 + - arm64 + - arm + overrides: + - goos: linux + goarch: arm + goarm: "6" + env: + - CC=arm-linux-gnueabi-gcc + - goos: linux + goarch: arm64 + env: + - CC=aarch64-linux-gnu-gcc + - goos: linux + goarch: amd64 + env: + - cc=gcc + +checksum: + name_template: 'checksums.txt' + +snapshot: + name_template: "{{ incpatch .Version }}-next" + +archives: + - name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + files: + - LICENSE + +changelog: + sort: asc + use: github + filters: + exclude: + - '^test:' + - '^chore' + - 'merge conflict' + - 'Merge pull request' + - 'Merge remote-tracking branch' + - 'Merge branch' + - 'go mod tidy' + +dockers: + - image_templates: + - "hrshadhin/{{ .ProjectName }}:{{ .Version }}-amd64" + dockerfile: Dockerfile_gr + use: buildx + build_flag_templates: + - "--pull" + - "--build-arg=BUILD_VERSION={{.Version}}" + - "--build-arg=BUILD_TIME={{.Date}}" + - "--platform=linux/amd64" + - image_templates: + - "hrshadhin/{{ .ProjectName }}:{{ .Version }}-arm64" + dockerfile: Dockerfile_gr + use: buildx + build_flag_templates: + - "--pull" + - "--build-arg=BUILD_VERSION={{.Version}}" + - "--build-arg=BUILD_TIME={{.Date}}" + - "--platform=linux/arm64" + goarch: arm64 + - image_templates: + - "hrshadhin/{{ .ProjectName }}:{{ .Version }}-arm" + dockerfile: Dockerfile_gr + use: buildx + build_flag_templates: + - "--pull" + - "--build-arg=BUILD_VERSION={{.Version}}" + - "--build-arg=BUILD_TIME={{.Date}}" + - "--platform=linux/arm/v6" + goarch: arm + +docker_manifests: + - name_template: "hrshadhin/{{ .ProjectName }}:{{ .Version }}" + image_templates: + - "hrshadhin/{{ .ProjectName }}:{{ .Version }}-amd64" + - "hrshadhin/{{ .ProjectName }}:{{ .Version }}-arm64" + - "hrshadhin/{{ .ProjectName }}:{{ .Version }}-arm" + - name_template: "hrshadhin/{{ .ProjectName }}:latest" + image_templates: + - "hrshadhin/{{ .ProjectName }}:{{ .Version }}-amd64" + - "hrshadhin/{{ .ProjectName }}:{{ .Version }}-arm64" + - "hrshadhin/{{ .ProjectName }}:{{ .Version }}-arm" + +release: + footer: | + **Full Changelog**: https://github.com/hrshadhin/ot-recorder/compare/{{ .PreviousTag }}...{{ .Tag }} diff --git a/Dockerfile b/Dockerfile index 611149e..f21b99a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,21 +17,29 @@ ADD . . # Build the Go app ARG BUILD_VERSION=0.0.1 -ARG BUILD_TIME=00000000-000000 +ARG BUILD_TIME=2022-12-13T000000Z RUN go generate ./cmd && GOOS=linux GOARCH=amd64 go build -ldflags "-w -s -X ot-recorder/app.Version=$BUILD_VERSION -X ot-recorder/app.BuildTime=$BUILD_TIME" -o ot-recorder . # Minimal image for running the application FROM alpine as final +ARG BUILD_VERSION=0.0.1 +ARG BUILD_TIME=2022-12-13T000000Z -LABEL org.opencontainers.image.source="https://github.com/hrshadhin/ot-recoder" \ +LABEL org.opencontainers.image.created=$BUILD_TIME \ + org.opencontainers.image.version=$BUILD_VERSION \ + org.opencontainers.image.source="https://github.com/hrshadhin/ot-recoder" \ org.opencontainers.image.url="https://github.com/hrshadhin/ot-recoder" \ - org.opencontainers.image.title="A note taking applications" + org.opencontainers.image.name="ot-recorder" \ + org.opencontainers.image.title="OwnTracks Recorder" \ + org.opencontainers.image.description="Store and access data published by OwnTracks apps" # Install/Create dependent tools,location,directory -RUN apk add --no-cache curl tini && \ +RUN apk add --no-cache curl tini tzdata && \ rm -rf /var/cache/apk/* && \ mkdir /persist && chown -R 1000:1000 /persist +ENV ZONEINFO=/usr/share/zoneinfo + # Import the compiled executable from the first stage. COPY --from=builder /build/ot-recorder /app/ot-recorder diff --git a/Dockerfile_gr b/Dockerfile_gr new file mode 100644 index 0000000..7fc9e67 --- /dev/null +++ b/Dockerfile_gr @@ -0,0 +1,34 @@ +FROM alpine + +ARG BUILD_VERSION=0.0.1 +ARG BUILD_TIME=2022-12-13T000000Z + +LABEL org.opencontainers.image.created=$BUILD_TIME \ + org.opencontainers.image.version=$BUILD_VERSION \ + org.opencontainers.image.source="https://github.com/hrshadhin/ot-recoder" \ + org.opencontainers.image.url="https://github.com/hrshadhin/ot-recoder" \ + org.opencontainers.image.name="ot-recorder" \ + org.opencontainers.image.title="OwnTracks Recorder" \ + org.opencontainers.image.description="Store and access data published by OwnTracks apps" + +# Install/Create dependent tools,location,directory +RUN apk add --no-cache curl tini tzdata && \ + rm -rf /var/cache/apk/* && \ + mkdir /persist && chown -R 1000:1000 /persist + +ENV ZONEINFO=/usr/share/zoneinfo + +## Open port +EXPOSE 8000 + +## Perform any further action as an unprivileged location. +USER 1000 +WORKDIR /app +COPY --chmod=0755 ot-recorder ot-recorder + + +HEALTHCHECK --interval=1m --timeout=1s --retries=3 --start-period=2s CMD ["curl", "--fail", "http://localhost:8000/health"] + +## Run the compiled binary. +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["/app/ot-recorder","--config","/app/config.yml", "serve"] diff --git a/LICENSE.md b/LICENSE similarity index 100% rename from LICENSE.md rename to LICENSE diff --git a/Makefile b/Makefile index e683dda..7a45667 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,11 @@ #!/usr/bin/env bash BUILD_VERSION := $(shell git describe --always --tags) -BUILD_TIME=$(shell date '+%Y%m%d-%H%M%S') -DOCKER_IMAGE_NAME="hrshadhin/ot-recoder" -BINARY_NAME=ot-recoder +BUILD_TIME=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') +DOCKER_IMAGE_NAME="hrshadhin/ot-recorder" +BINARY_NAME=ot-recorder BIN_OUT_DIR=bin +GO_VERSION=1.19 export PATH=$(shell go env GOPATH)/bin:$(shell echo $$PATH) @@ -45,7 +46,8 @@ dl-deps: ## Get dependencies build: clean ## Build binary go generate ./cmd - go build -v -ldflags="-w -s -X ot-recorder/app.Version=${BUILD_VERSION} -X ot-recorder/app.BuildTime=${BUILD_TIME}" -o $(BIN_OUT_DIR)/$(BINARY_NAME) + go build -v -tags osusergo,netgo,sqlite_omit_load_extension \ + -ldflags="-extldflags=-static -w -s -X ot-recorder/app.Version=${BUILD_VERSION} -X ot-recorder/app.BuildTime=${BUILD_TIME}" -o $(BIN_OUT_DIR)/$(BINARY_NAME) version: ## Check binary version ./$(BIN_OUT_DIR)/$(BINARY_NAME) --version @@ -65,7 +67,7 @@ migrate-down: ## Revert migration ./$(BIN_OUT_DIR)/$(BINARY_NAME) migrate down docker-build: ## Build docker image - docker build --build-arg BUILD_VERSION=${BUILD_VERSION} --build-arg BUILD_TIME=${BUILD_TIME} --tag ${DOCKER_IMAGE_NAME} . + docker build --build-arg GO_VERSION=${GO_VERSION} --build-arg BUILD_VERSION=${BUILD_VERSION} --build-arg BUILD_TIME=${BUILD_TIME} --tag ${DOCKER_IMAGE_NAME} . docker-push: ## Push docker image docker push @@ -78,5 +80,5 @@ docker-run: ## Run docker image with sqlite -v $$(pwd)/data:/persist \ $(DOCKER_IMAGE_NAME):latest -docker-migrate: ## Run migrations inside dorker - docker exec ot-recoder /app/ot-recoder migrate up +docker-migrate: ## Run migrations inside docker + docker exec ot-recoder /app/ot-recorder migrate up diff --git a/_deploy/docker/README.md b/_deploy/docker/README.md index 98d17fa..1135f5b 100644 --- a/_deploy/docker/README.md +++ b/_deploy/docker/README.md @@ -11,5 +11,5 @@ sudo chown -R 1000:1000 data docker-compose up -d # run migrations -docker-compose exec owntracks-recoder /app/ot-recoder migrate up +docker-compose exec owntracks-recorder /app/ot-recorder migrate up ``` diff --git a/_deploy/docker/docker-compose.yml b/_deploy/docker/docker-compose.yml index 2f9c331..eba4f6b 100644 --- a/_deploy/docker/docker-compose.yml +++ b/_deploy/docker/docker-compose.yml @@ -2,8 +2,8 @@ version: "3.5" services: owntracks-recoder: - image: hrshadhin/ot-recoder - container_name: owntracks-recoder + image: hrshadhin/ot-recorder + container_name: owntracks-recorder restart: unless-stopped volumes: - ${PWD}/config.yml:/app/config.yml diff --git a/app/server/serve.go b/app/server/serve.go index c8dca79..27919a3 100644 --- a/app/server/serve.go +++ b/app/server/serve.go @@ -119,7 +119,7 @@ func printBanner() { log.Println("| | | \\ \\ /\\ / / '_ \\| || '__/ _` |/ __| |/ / __| | |_) / _ \\/ __|") log.Println("| |_| |\\ V V /| | | | || | | (_| | (__| <\\__ \\ | _ < __/ (__ _") log.Println(" \\___/ \\_/\\_/ |_| |_|_||_| \\__,_|\\___|_|\\_\\___/ |_| \\_\\___|\\___(_)") - log.Println(" ") - log.Printf(" Version: %-18s Build time: %-18s ", app.Version, app.BuildTime) + log.Println(" ") + log.Printf(" Version: %-10s Build time: %-10s", app.Version, app.BuildTime) log.Println("<<=") }