Skip to content

Commit

Permalink
refactor(all): refactor code
Browse files Browse the repository at this point in the history
refactor code

Signed-off-by: mritd <[email protected]>
  • Loading branch information
mritd committed Jul 5, 2021
1 parent 09d5df9 commit b63f38c
Show file tree
Hide file tree
Showing 6 changed files with 567 additions and 111 deletions.
32 changes: 32 additions & 0 deletions .cross_compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -e

DIST_PREFIX="idgen"
TARGET_DIR="dist"
PLATFORMS="darwin/amd64 darwin/arm64 linux/386 linux/amd64 linux/arm linux/arm64"

BUILD_VERSION=$(cat version)
BUILD_DATE=$(date "+%F %T")
COMMIT_SHA1=$(git rev-parse HEAD)

rm -rf ${TARGET_DIR}
mkdir ${TARGET_DIR}

for pl in ${PLATFORMS}; do
export GOOS=$(echo ${pl} | cut -d'/' -f1)
export GOARCH=$(echo ${pl} | cut -d'/' -f2)
export CGO_ENABLED=0
export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH}
if [ "${GOOS}" == "windows" ]; then
export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH}.exe
fi

echo "build => ${TARGET}"
go build -trimpath -o ${TARGET} \
-ldflags "-X 'github.com/mritd/idgen/cmd.Version=${BUILD_VERSION}' \
-X 'github.com/mritd/idgen/cmd.BuildDate=${BUILD_DATE}' \
-X 'github.com/mritd/idgen/cmd.CommitID=${COMMIT_SHA1}'\
-w -s"
done

8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
FROM golang:1.14.2-alpine3.11 AS builder
FROM golang:1.16-alpine AS builder

COPY . /go/src/github.com/mritd/idgen

WORKDIR /go/src/github.com/mritd/idgen

ENV GO111MODULE on
ENV GOPROXY https://goproxy.cn

RUN set -ex \
&& apk upgrade \
&& apk add git \
Expand All @@ -19,7 +16,7 @@ RUN set -ex \
-X 'github.com/mritd/idgen/cmd.BuildDate=${BUILD_DATE}' \
-X 'github.com/mritd/idgen/cmd.CommitID=${COMMIT_SHA1}'"

FROM alpine:3.11 AS dist
FROM alpine AS dist

LABEL maintainer="mritd <[email protected]>"

Expand All @@ -37,4 +34,5 @@ RUN set -ex \
COPY --from=builder /go/bin/idgen /usr/bin/idgen

ENTRYPOINT ["idgen"]

CMD ["server"]
13 changes: 3 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ BUILD_DATE := $(shell date "+%F %T")
COMMIT_SHA1 := $(shell git rev-parse HEAD)

all:
gox -osarch="darwin/amd64 linux/386 linux/amd64" \
-output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" \
-ldflags "-X 'github.com/mritd/idgen/cmd.Version=${BUILD_VERSION}' \
-X 'github.com/mritd/idgen/cmd.BuildDate=${BUILD_DATE}' \
-X 'github.com/mritd/idgen/cmd.CommitID=${COMMIT_SHA1}'"
bash .cross_compile.sh

release: all
ghr -u mritd -t $(GITHUB_TOKEN) -replace -recreate --debug ${BUILD_VERSION} dist
ghr -u mritd -t $(GITHUB_TOKEN) -replace -recreate -name "Bump v${BUILD_VERSION}" --debug ${BUILD_VERSION} dist

pre-release: all
ghr -u mritd -t $(GITHUB_TOKEN) -replace -recreate -prerelease --debug ${BUILD_VERSION} dist
ghr -u mritd -t $(GITHUB_TOKEN) -replace -recreate -prerelease -name "Bump v${BUILD_VERSION}" --debug ${BUILD_VERSION} dist

clean:
rm -rf dist
Expand All @@ -29,6 +25,3 @@ docker:
.PHONY: all release clean install

.EXPORT_ALL_VARIABLES:

GO111MODULE = on
GOPROXY = https://goproxy.cn
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/mritd/idgen

go 1.14
go 1.16

require (
github.com/atotto/clipboard v0.1.2
github.com/mritd/chinaid v1.0.2
github.com/spf13/cobra v1.0.0
github.com/atotto/clipboard v0.1.4
github.com/mritd/chinaid v1.0.3
github.com/spf13/cobra v1.2.1
)
Loading

0 comments on commit b63f38c

Please sign in to comment.