Skip to content

Commit

Permalink
fix: #240 (#242)
Browse files Browse the repository at this point in the history
* fix: #240

* fix: #241 (#243)

* fix: #244 (#246)

* feat: #249 (#250)

* feat: #249

* fix: #247, goreleaser with cgo
  • Loading branch information
asabya authored Sep 5, 2022
1 parent 5cfab47 commit 065ed98
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 145 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Release

defaults:
run:
shell: bash

on:
push:
branches-ignore:
Expand All @@ -21,17 +25,16 @@ jobs:
fetch-depth: 0
- name: Fetch all tags
run: git fetch --force --tags
- name: Docker Hub Login
run: |
printf ${{ secrets.DOCKERHUB_TOKEN }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: setup release environment
run: |-
echo '${{secrets.DOCKERHUB_USERNAME}}:${{secrets.DOCKERHUB_TOKEN}}:docker.io' > .docker-creds
echo 'DOCKER_CREDS_FILE=.docker-creds' > .release-env
echo 'GITHUB_TOKEN=${{secrets.GITHUB_TOKEN}}' >> .release-env
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |-
sudo rm -rf dist
make release
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ _cgo_export.*

.DS_Store
cover.html
cover.out
cover.out

# goreleaser environment resources
.release-env
.docker-creds
139 changes: 53 additions & 86 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,120 +2,106 @@ project_name: dfs

release:
prerelease: auto

env:
- GO111MODULE=on
- CGO_ENABLED=1
before:
hooks:
- go mod download
builds:
- id: dfs-linux
- id: dfs-darwin-amd64
main: ./cmd/dfs
binary: dfs
flags:
- -v
- -trimpath
ldflags:
- -s -w
- -X github.com/fairdatasociety/fairOS-dfs.commit={{ .ShortCommit }}
- -X github.com/fairdatasociety/fairOS-dfs.version={{ .Version }}
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- 386
- arm64
- arm
goarm:
- 7
- id: dfs-darwin
main: ./cmd/dfs
binary: dfs
env:
- CC=o64-clang
- CXX=o64-clang++
flags:
- -v
- -trimpath
ldflags:
- -s -w
- -X github.com/fairdatasociety/fairOS-dfs.commit={{ .ShortCommit }}
- -X github.com/fairdatasociety/fairOS-dfs.version={{ .Version }}
env:
- CGO_ENABLED=0
- -linkmode=external
- id: dfs-darwin-arm64
main: ./cmd/dfs
binary: dfs
goos:
- darwin
goarch:
- amd64
- arm64
- id: dfs-windows
main: ./cmd/dfs
binary: dfs
env:
- CC=oa64-clang
- CXX=oa64-clang++
flags:
- -v
- -trimpath
ldflags:
- -s -w
- -X github.com/fairdatasociety/fairOS-dfs.commit={{ .ShortCommit }}
- -X github.com/fairdatasociety/fairOS-dfs.version={{ .Version }}
env:
- CGO_ENABLED=0
- -linkmode=external
- id: dfs-linux-amd64
main: ./cmd/dfs
binary: dfs
goos:
- windows
- linux
goarch:
- amd64
- 386

- id: dfs-cli-linux
main: ./cmd/dfs-cli
binary: dfs_cli
env:
- CC=x86_64-linux-gnu-gcc
- CXX=x86_64-linux-gnu-g++
flags:
- -v
- -trimpath
ldflags:
- -s -w
- -X github.com/fairdatasociety/fairOS-dfs.commit={{ .ShortCommit }}
- -X github.com/fairdatasociety/fairOS-dfs.version={{ .Version }}
env:
- CGO_ENABLED=0
- -linkmode=external
- -extldflags "-lc -lrt -lpthread --static"
- id: dfs-linux-arm64
main: ./cmd/dfs
binary: dfs
goos:
- linux
goarch:
- amd64
- 386
- arm64
- arm
goarm:
- 7
- id: dfs-cli-darwin
main: ./cmd/dfs-cli
binary: dfs_cli
env:
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
flags:
- -v
- -trimpath
ldflags:
- -s -w
- -X github.com/fairdatasociety/fairOS-dfs.commit={{ .ShortCommit }}
- -X github.com/fairdatasociety/fairOS-dfs.version={{ .Version }}
env:
- CGO_ENABLED=0
- -linkmode=external
- -extldflags "-lc -lrt -lpthread --static"
- id: dfs-windows-amd64
main: ./cmd/dfs
binary: dfs
goos:
- darwin
- windows
goarch:
- amd64
- arm64
- id: dfs-cli-windows
main: ./cmd/dfs-cli
binary: dfs_cli
env:
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
flags:
- -v
- -trimpath
- -buildmode=exe
ldflags:
- -s -w
- -X github.com/fairdatasociety/fairOS-dfs.commit={{ .ShortCommit }}
- -X github.com/fairdatasociety/fairOS-dfs.version={{ .Version }}
env:
- CGO_ENABLED=0
goos:
- windows
goarch:
- amd64
- 386

- -linkmode=external
archives:
- id: binary
name_template: '{{ .Binary }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}'
Expand All @@ -132,7 +118,7 @@ dockers:
- "fairdatasociety/fairos-dfs:v{{ .Version }}-amd64"
use: buildx
ids:
- dfs-linux
- dfs-linux-amd64
goarch: amd64
dockerfile: Dockerfile.goreleaser
build_flag_templates:
Expand All @@ -143,29 +129,14 @@ dockers:
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- image_templates:
- "fairdatasociety/fairos-dfs:v{{ .Version }}-armv7"
use: buildx
ids:
- dfs-linux
goarch: arm
goarm: 7
dockerfile: Dockerfile.goreleaser
build_flag_templates:
- "--platform=linux/arm/v7"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- image_templates:
- "fairdatasociety/fairos-dfs:v{{ .Version }}-arm64v8"
- "fairdatasociety/fairos-dfs:v{{ .Version }}-arm64"
use: buildx
ids:
- dfs-linux
- dfs-linux-arm64
goarch: arm64
dockerfile: Dockerfile.goreleaser
build_flag_templates:
- "--platform=linux/arm64/v8"
- "--platform=linux/arm64"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
Expand All @@ -175,22 +146,18 @@ docker_manifests:
- name_template: fairdatasociety/fairos-dfs:v{{ .Major }}
image_templates:
- fairdatasociety/fairos-dfs:v{{ .Version }}-amd64
- fairdatasociety/fairos-dfs:v{{ .Version }}-armv7
- fairdatasociety/fairos-dfs:v{{ .Version }}-arm64v8
- fairdatasociety/fairos-dfs:v{{ .Version }}-arm64
skip_push: auto
- name_template: fairdatasociety/fairos-dfs:v{{ .Major }}.{{ .Minor }}
image_templates:
- fairdatasociety/fairos-dfs:v{{ .Version }}-amd64
- fairdatasociety/fairos-dfs:v{{ .Version }}-armv7
- fairdatasociety/fairos-dfs:v{{ .Version }}-arm64v8
- fairdatasociety/fairos-dfs:v{{ .Version }}-arm64
skip_push: auto
- name_template: fairdatasociety/fairos-dfs:v{{ .Major }}.{{ .Minor }}.{{ .Patch }}{{ with .Prerelease }}-{{ . }}{{ end }}
image_templates:
- fairdatasociety/fairos-dfs:v{{ .Version }}-amd64
- fairdatasociety/fairos-dfs:v{{ .Version }}-armv7
- fairdatasociety/fairos-dfs:v{{ .Version }}-arm64v8
- fairdatasociety/fairos-dfs:v{{ .Version }}-arm64
- name_template: fairdatasociety/fairos-dfs:latest
image_templates:
- fairdatasociety/fairos-dfs:v{{ .Version }}-amd64
- fairdatasociety/fairos-dfs:v{{ .Version }}-armv7
- fairdatasociety/fairos-dfs:v{{ .Version }}-arm64v8
- fairdatasociety/fairos-dfs:v{{ .Version }}-arm64
12 changes: 4 additions & 8 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
FROM alpine:3.15
FROM debian:bullseye

ARG CONFIG
ENV CONFIG=$CONFIG
RUN apt-get update
RUN apt-get install -y ca-certificates
RUN update-ca-certificates

RUN addgroup -g 10000 fds
RUN adduser -u 10000 -G fds -h /home/fds -D fds

USER fds
RUN if [ -n "$CONFIG" ]; then echo -e "$CONFIG" > ~/.dfs.yaml; fi
EXPOSE 9090

COPY dfs /usr/local/bin/dfs
Expand Down
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ GOGOPROTOBUF ?= protoc-gen-gogofaster
GOGOPROTOBUF_VERSION ?= v1.3.1

COMMIT ?= "$(shell git describe --long --dirty --always --match "" || true)"
LDFLAGS ?= -s -w -X github.com/fairdatasociety/fairOS-dfs.commit="$(COMMIT)"
VERSION ?= "$(shell git describe --tags --abbrev=0 || true)"
LDFLAGS ?= -s -w -X github.com/fairdatasociety/fairOS-dfs.commit="$(COMMIT)" -X github.com/fairdatasociety/fairOS-dfs.version="$(VERSION)"

.PHONY: all
all: build lint vet test-race binary
Expand Down Expand Up @@ -63,4 +64,25 @@ clean:
$(GO) clean
rm -rf dist/

.PHONY: release
release:
docker run --rm --privileged \
--env-file .release-env \
-v ~/go/pkg/mod:/go/pkg/mod \
-v `pwd`:/go/src/github.com/asabya/fairOS-dfs \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/asabya/fairOS-dfs \
ghcr.io/goreleaser/goreleaser-cross:v1.19.0 release --rm-dist

.PHONY: release-dry-run
release-dry-run:
docker run --rm --privileged \
-v ~/go/pkg/mod:/go/pkg/mod \
-v `pwd`:/go/src/github.com/asabya/fairOS-dfs \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/asabya/fairOS-dfs \
ghcr.io/goreleaser/goreleaser-cross:v1.19.0 release --rm-dist \
--skip-validate=true \
--skip-publish

FORCE:
37 changes: 1 addition & 36 deletions cmd/dfs/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,42 +204,7 @@ func startHttpService(logger logging.Logger) {

// Web page handlers
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, err := fmt.Fprintln(w, "FairOS-dfs")
if err != nil {
logger.Errorf("error in API /: ", err)
return
}
_, err = fmt.Fprintln(w, dfs.Version)
if err != nil {
logger.Errorf("error in API /: ", err)
return
}
_, err = fmt.Fprintln(w, beeApi)
if err != nil {
logger.Errorf("error in API /: ", err)
return
}
_, err = fmt.Fprintln(w, verbosity)
if err != nil {
logger.Errorf("error in API /: ", err)
return
}
_, err = fmt.Fprintln(w, httpPort)
if err != nil {
logger.Errorf("error in API /: ", err)
return
}
_, err = fmt.Fprintln(w, pprofPort)
if err != nil {
logger.Errorf("error in API /: ", err)
return
}
_, err = fmt.Fprintln(w, cookieDomain)
if err != nil {
logger.Errorf("error in API /: ", err)
return
}
_, err = fmt.Fprintln(w, corsOrigins)
_, err := fmt.Fprintln(w, "OK")
if err != nil {
logger.Errorf("error in API /: ", err)
return
Expand Down
Loading

0 comments on commit 065ed98

Please sign in to comment.