Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattheis committed Mar 5, 2024
1 parent a26a7c3 commit d3a6ae5
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 102 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/docker/Dockerfile.dev
/docker/Dockerfile
/ui/node_modules/
.idea/
build/
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: build
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: 1.22.x
- uses: actions/setup-node@v4
with:
node-version: '20'
- uses: actions/checkout@v4
- run: make download-tools
- run: make install
- run: make generate
- run: make lint
- run: make test
- run: make bulid-js
- run: make release
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
dist/
build
vendor
coverage.txt
Expand Down
99 changes: 99 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
project_name: traggo
builds:
- id: linux-amd64
main: ./
goos:
- linux
goarch:
- 'amd64'
flags: ['-tags="netgo osusergo sqlite_omit_load_extension"']
ldflags: ["-s","-w","-linkmode","external","-extldflags","-static","-X main.BuildDate={{.Date}}","-X main.BuildMode=prod","-X main.BuildCommit={{.Commit}}","-X main.BuildVersion={{.Version}}"]
- id: linux-armhf
main: ./
goos: [linux]
goarch: [arm]
goarm: [7]
env: [CC=arm-linux-gnueabihf-gcc, CXX=arm-linux-gnueabihf-g++]
flags: ['-tags="netgo osusergo sqlite_omit_load_extension"']
ldflags: ["-s","-w","-linkmode","external","-extldflags","-static","-X main.BuildDate={{.Date}}","-X main.BuildMode=prod","-X main.BuildCommit={{.Commit}}","-X main.BuildVersion={{.Version}}"]
- id: linux-arm64
main: ./
goos: [linux]
goarch: [arm64]
env: [CC=aarch64-linux-gnu-gcc, CXX=aarch64-linux-gnu-g++]
flags: ['-tags="netgo osusergo sqlite_omit_load_extension"']
ldflags: ["-s","-w","-linkmode","external","-extldflags","-static","-X main.BuildDate={{.Date}}","-X main.BuildMode=prod","-X main.BuildCommit={{.Commit}}","-X main.BuildVersion={{.Version}}"]
- id: windows-amd64
main: ./
goos: [windows]
goarch: [amd64]
env: [CC=x86_64-w64-mingw32-gcc, CXX=x86_64-w64-mingw32-gcc]
flags: ['-tags="netgo osusergo sqlite_omit_load_extension"']
ldflags: ["-s","-w","-linkmode","external","-extldflags","-static","-X main.BuildDate={{.Date}}","-X main.BuildMode=prod","-X main.BuildCommit={{.Commit}}","-X main.BuildVersion={{.Version}}"]
archives:
- files:
- LICENSE
- README.md
- .env.sample
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{- if eq .Arch "386" }}i386{{- else }}{{ .Arch }}{{ end }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format_overrides:
- goos: windows
format: zip
checksum:
disable: true
changelog:
skip: true
dockers:
- use: buildx
goos: linux
goarch: amd64
goarm: ""
image_templates:
- "traggo/server:amd64-latest"
- "traggo/server:amd64-{{ .RawVersion }}"
dockerfile: docker/Dockerfile
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- use: buildx
goos: linux
goarch: arm64
goarm: ""
image_templates:
- "traggo/server:arm64-latest"
- "traggo/server:arm64-{{ .RawVersion }}"
dockerfile: docker/Dockerfile
build_flag_templates:
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- use: buildx
goos: linux
goarch: arm
goarm: 7
image_templates:
- "traggo/server:armv7-latest"
- "traggo/server:armv7-{{ .RawVersion }}"
dockerfile: docker/Dockerfile
build_flag_templates:
- "--platform=linux/arm/v7"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
docker_manifests:
- name_template: "traggo/server:latest"
image_templates:
- "screego/server:amd64-latest"
- "screego/server:arm64-latest"
- "screego/server:armv7-latest"
- name_template: "traggo/server:{{ .RawVersion }}"
image_templates:
- "screego/server:amd64-{{ .RawVersion }}"
- "screego/server:arm64-{{ .RawVersion }}"
- "screego/server:armv7-{{ .RawVersion }}"
112 changes: 12 additions & 100 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,9 @@ COMMIT=$(shell git rev-parse --verify HEAD)
DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LD_FLAGS=-s -w -linkmode external -extldflags "-static" -X main.BuildDate=$(DATE) -X main.BuildMode=prod -X main.BuildCommit=$(COMMIT) -X main.BuildVersion=$(VERSION)
BUILD_DIR=./build
BUILD_LICENSE=${BUILD_DIR}/license/3RD_PARTY_LICENSES
UI_BUILD_LICENSE=${BUILD_DIR}/license/UI_3RD_PARTY_LICENSES
PWD=$(shell pwd)
GO_VERSION=1.13.1
DOCKER_BUILD_IMAGE=traggo/build
DOCKER_WORKDIR=/proj
GOPATH_VOLUME=-v "`go env GOPATH`/pkg/mod/:/go/pkg/mod"
WORKDIR_VOLUME=-v "${PWD}/:${DOCKER_WORKDIR}"
DOCKER_GO_BUILD=go build -a -installsuffix cgo -ldflags '${LD_FLAGS}' -tags '${TAGS}'
DOCKER_RUN=docker run --rm ${WORKDIR_VOLUME} ${GOPATH_VOLUME} -w ${DOCKER_WORKDIR}
NEW_IMAGE_NAME=traggo/server
DOCKER_MANIFEST=DOCKER_CLI_EXPERIMENTAL=enabled docker manifest
BIN_PREFIX=traggo-server
GOLANG_CROSS_VERSION=v1.22.0

license-dir:
mkdir -p build/license || true
Expand Down Expand Up @@ -77,98 +67,20 @@ packr-clean:

pre-build: build-js packr

build-bin-local: pre-build
build-bin-local:
CGO_ENABLED=1 go build -a -ldflags '${LD_FLAGS}' -tags '${TAGS}' -o ${BUILD_DIR}/traggo-server

build-bin-linux-amd64: pre-build
${DOCKER_RUN} ${DOCKER_BUILD_IMAGE}:$(GO_VERSION)-linux-amd64 ${DOCKER_GO_BUILD} -o ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-amd64 ${DOCKER_WORKDIR}
.PHONY: release
release:
docker run \
--rm \
-e CGO_ENABLED=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $$PWD:/work \
-w /work \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean --snapshot

build-docker-linux-amd64:
cp ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-amd64 docker/traggo && docker build -t ${NEW_IMAGE_NAME}:amd64-latest -t ${NEW_IMAGE_NAME}:amd64-${VERSION} docker/ && rm docker/traggo

build-bin-linux-386: pre-build
${DOCKER_RUN} ${DOCKER_BUILD_IMAGE}:$(GO_VERSION)-linux-386 ${DOCKER_GO_BUILD} -o ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-386 ${DOCKER_WORKDIR}

build-docker-linux-386:
cp ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-386 docker/traggo && docker build -t ${NEW_IMAGE_NAME}:386-latest -t ${NEW_IMAGE_NAME}:386-${VERSION} docker/ && rm docker/traggo

build-bin-linux-arm-7: pre-build
${DOCKER_RUN} ${DOCKER_BUILD_IMAGE}:$(GO_VERSION)-linux-arm-7 ${DOCKER_GO_BUILD} -o ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-arm-7 ${DOCKER_WORKDIR}

build-docker-linux-arm-7:
cp ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-arm-7 docker/traggo && docker build -t ${NEW_IMAGE_NAME}:arm-7-latest -t ${NEW_IMAGE_NAME}:arm-7-${VERSION} docker/ && rm docker/traggo

build-bin-linux-arm64: pre-build
${DOCKER_RUN} ${DOCKER_BUILD_IMAGE}:$(GO_VERSION)-linux-arm64 ${DOCKER_GO_BUILD} -o ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-arm64 ${DOCKER_WORKDIR}

build-docker-linux-arm64:
cp ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-arm64 docker/traggo && docker build -t ${NEW_IMAGE_NAME}:arm64-latest -t ${NEW_IMAGE_NAME}:arm64-${VERSION} docker/ && rm docker/traggo

build-bin-windows-amd64: pre-build
${DOCKER_RUN} ${DOCKER_BUILD_IMAGE}:$(GO_VERSION)-windows-amd64 ${DOCKER_GO_BUILD} -o ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-windows-amd64.exe ${DOCKER_WORKDIR}

build-bin-windows-386: pre-build
${DOCKER_RUN} ${DOCKER_BUILD_IMAGE}:$(GO_VERSION)-windows-386 ${DOCKER_GO_BUILD} -o ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-windows-386.exe ${DOCKER_WORKDIR}

build-bin-linux-ppc64le: pre-build
${DOCKER_RUN} ${DOCKER_BUILD_IMAGE}:$(GO_VERSION)-linux-ppc64le ${DOCKER_GO_BUILD} -o ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-ppc64le ${DOCKER_WORKDIR}

build-docker-linux-ppc64le:
cp ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-ppc64le docker/traggo && docker build -t ${NEW_IMAGE_NAME}:ppc64le-latest -t ${NEW_IMAGE_NAME}:ppc64le-${VERSION} docker/ && rm docker/traggo

build-bin-linux-s390x: pre-build
${DOCKER_RUN} ${DOCKER_BUILD_IMAGE}:$(GO_VERSION)-linux-s390x ${DOCKER_GO_BUILD} -o ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-s390x ${DOCKER_WORKDIR}

build-docker-linux-s390x:
cp ${BUILD_DIR}/${BIN_PREFIX}-${VERSION}-linux-s390x docker/traggo && docker build -t ${NEW_IMAGE_NAME}:s390x-latest -t ${NEW_IMAGE_NAME}:s390x-${VERSION} docker/ && rm docker/traggo

build-bin: build-bin-linux-amd64 build-bin-linux-386 build-bin-linux-arm-7 build-bin-linux-arm64 build-bin-linux-ppc64le build-bin-linux-s390x build-bin-windows-amd64 build-bin-windows-386

build-docker: build-docker-linux-amd64 build-docker-linux-386 build-docker-linux-arm-7 build-docker-linux-arm64 build-docker-linux-ppc64le build-docker-linux-s390x

fix-build-owner:
sudo chown -R $(shell id -u):$(shell id -g) ${BUILD_DIR}

docker-login-ci:
docker login -u "$$DOCKER_USER" -p "$$DOCKER_PASS";

docker-push:
docker push --all-tags ${NEW_IMAGE_NAME}

docker-push-manifest:
${DOCKER_MANIFEST} create "${NEW_IMAGE_NAME}:latest" "${NEW_IMAGE_NAME}:amd64-latest" "${NEW_IMAGE_NAME}:386-latest" "${NEW_IMAGE_NAME}:arm-7-latest" "${NEW_IMAGE_NAME}:arm64-latest" "${NEW_IMAGE_NAME}:ppc64le-latest" "${NEW_IMAGE_NAME}:s390x-latest"
${DOCKER_MANIFEST} create "${NEW_IMAGE_NAME}:${VERSION}" "${NEW_IMAGE_NAME}:amd64-${VERSION}" "${NEW_IMAGE_NAME}:386-${VERSION}" "${NEW_IMAGE_NAME}:arm-7-${VERSION}" "${NEW_IMAGE_NAME}:arm64-${VERSION}" "${NEW_IMAGE_NAME}:ppc64le-${VERSION}" "${NEW_IMAGE_NAME}:s390x-${VERSION}"
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:latest" "${NEW_IMAGE_NAME}:amd64-latest" --os=linux --arch=amd64
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:${VERSION}" "${NEW_IMAGE_NAME}:amd64-${VERSION}" --os=linux --arch=amd64
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:latest" "${NEW_IMAGE_NAME}:386-latest" --os=linux --arch=386
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:${VERSION}" "${NEW_IMAGE_NAME}:386-${VERSION}" --os=linux --arch=386
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:latest" "${NEW_IMAGE_NAME}:arm-7-latest" --os=linux --arch=arm --variant=v7
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:${VERSION}" "${NEW_IMAGE_NAME}:arm-7-${VERSION}" --os=linux --arch=arm --variant=v7
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:latest" "${NEW_IMAGE_NAME}:arm64-latest" --os=linux --arch=arm64
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:${VERSION}" "${NEW_IMAGE_NAME}:arm64-${VERSION}" --os=linux --arch=arm64
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:latest" "${NEW_IMAGE_NAME}:ppc64le-latest" --os=linux --arch=ppc64le
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:${VERSION}" "${NEW_IMAGE_NAME}:ppc64le-${VERSION}" --os=linux --arch=ppc64le
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:latest" "${NEW_IMAGE_NAME}:s390x-latest" --os=linux --arch=s390x
${DOCKER_MANIFEST} annotate "${NEW_IMAGE_NAME}:${VERSION}" "${NEW_IMAGE_NAME}:s390x-${VERSION}" --os=linux --arch=s390x
${DOCKER_MANIFEST} push "${NEW_IMAGE_NAME}:${VERSION}"
${DOCKER_MANIFEST} push "${NEW_IMAGE_NAME}:latest"

licenses-ui: license-dir
(cd ui && yarn -s licenses generate-disclaimer --prod > ../${UI_BUILD_LICENSE})

licenses-go: license-dir
go mod vendor
echo "THE FOLLOWING SETS FORTH ATTRIBUTION NOTICES FOR THIRD PARTY SOFTWARE THAT MAY BE CONTAINED IN PORTIONS OF THE TRAGGO PRODUCT" > ${BUILD_LICENSE}
echo >> ${BUILD_LICENSE}
echo ------- >> ${BUILD_LICENSE}
echo >> ${BUILD_LICENSE}
(cd vendor && find . -type f \( -iname "LICENSE*" -o -iname "NOTICE*" \) -exec echo The following software may be included in this product {} \; -exec echo \; -exec cat {} \; -exec echo \; -exec echo -------- \; -exec echo \;) >> ${BUILD_LICENSE}

package-zip: licenses-ui licenses-go
find build/* -maxdepth 0 -type f -exec zip -9 -j {}.zip {} build/license/3RD_PARTY_LICENSES build/license/UI_3RD_PARTY_LICENSES LICENSE \;

build-compress:
find build/* -maxdepth 0 -type f -exec upx {} \;

install: install-go install-js

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM scratch
WORKDIR /opt/traggo
ADD traggo /opt/traggo
COPY traggo /opt/traggo
EXPOSE 3030
ENTRYPOINT ["./traggo"]

0 comments on commit d3a6ae5

Please sign in to comment.