Skip to content

Commit

Permalink
[release]: use goreleaser (easegress-io#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxx7xxxx committed Jun 2, 2021
1 parent 3436903 commit 29e1179
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 83 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ rootfs/alpine/opt
rootfs/ubuntu/opt

# Dirs default config creates if not existed.
logs
log
data
member

# MacOS stuff.
.DS_Store
Expand All @@ -20,4 +21,7 @@ data
# vscode
.vscode/

# goreleaser
dist/

easegress.pid
71 changes: 71 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

snapshot:
name_template: '{{ .Tag }}'
checksum:
name_template: 'checksums.txt'
changelog:
skip: true

builds:
- id: client
main: cmd/client/main.go
binary: bin/egctl
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
ldflags:
- -s -w
- -X github.com/megaease/easegress/pkg/version.RELEASE=v1.0.0
- -X github.com/megaease/easegress/pkg/version.COMMIT={{.Commit}}
- -X github.com/megaease/easegress/pkg/version.REPO=megaease/easegress

- id: server
main: cmd/server/main.go
binary: bin/easegress-server
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
ldflags:
- -s -w
- -X github.com/megaease/easegress/pkg/version.RELEASE=v1.0.0
- -X github.com/megaease/easegress/pkg/version.COMMIT={{.Commit}}
- -X github.com/megaease/easegress/pkg/version.REPO=megaease/easegress

archives:
- id: easegress
format: tar.gz
name_template: "{{ .ProjectName }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}"
files:
- none*

release:
github:
owner: megaease
name: easegress
name_template: "{{ .ProjectName }}-v{{ .Version }}"

dockers:
- image_templates:
- megaease/easegress:latest
- megaease/easegress:{{ .Tag }}

goos: linux
goarch: amd64
ids:
- client
- server

dockerfile: build/package/Dockerfile.goreleaser

extra_files:
- build/package/entrypoint.sh
2 changes: 1 addition & 1 deletion rootfs/alpine/Dockerfile.server → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.6
FROM alpine:3.13

COPY . /
RUN apk add --no-cache tini libc6-compat && chmod +x /entrypoint.server.sh && chmod +x /opt/easegress/bin/*
Expand Down
51 changes: 11 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
SHELL:=/bin/bash
.PHONY: build build_client build_server \
build_client_alpine build_server_alpine build_server_ubuntu \
run fmt vet clean \
mod_update vendor_from_mod vendor_clean test
SHELL:=/bin/sh
.PHONY: build build_client build_server build_docker \
test run fmt vet clean \
mod_update vendor_from_mod vendor_clean

export GO111MODULE=on
export GOPROXY=https:https://goproxy.io
Expand All @@ -13,20 +12,17 @@ MKFILE_DIR := $(dir $(MKFILE_PATH))

# Version
RELEASE?=1.0.0

# Git Related
GIT_REPO_INFO=$(shell cd ${MKFILE_DIR} && git config --get remote.origin.url)
ifndef GIT_COMMIT
GIT_COMMIT := git-$(shell git rev-parse --short HEAD)
endif

# Docker Related
DOCKER=docker
DOCKER_REPO_INFO?=megaease/easegress

# Source Files
ALL_FILES = $(shell find ${MKFILE_DIR}{cmd,pkg} -type f -name "*.go")
CLIENT_FILES = $(shell find ${MKFILE_DIR}{cmd/client,pkg} -type f -name "*.go")
SERVER_FILES = $(shell find ${MKFILE_DIR}{cmd/server,pkg} -type f -name "*.go")
ALL_FILES = $(shell find ${MKFILE_DIR}${cmd,pkg} -type f -name "*.go")
CLIENT_FILES = $(shell find ${MKFILE_DIR}${cmd/client,pkg} -type f -name "*.go")
SERVER_FILES = $(shell find ${MKFILE_DIR}${cmd/server,pkg} -type f -name "*.go")

# Targets
TARGET_SERVER=${MKFILE_DIR}bin/easegress-server
Expand All @@ -40,26 +36,8 @@ build_client: ${TARGET_CLIENT}

build_server: ${TARGET_SERVER}

build_client_alpine: ${TARGET_CLIENT}
@echo "build client docker image (from alpine)"
rm -rf ${MKFILE_DIR}rootfs/alpine/opt && \
mkdir -p ${MKFILE_DIR}rootfs/alpine/opt/easegress/bin && \
cp ${TARGET_CLIENT} ${MKFILE_DIR}rootfs/alpine/opt/easegress/bin && \
cd ${MKFILE_DIR}rootfs/alpine && $(DOCKER) build -t ${DOCKER_REPO_INFO}:client-${RELEASE}_alpine -f ./Dockerfile.client .

build_server_alpine: ${TARGET_SERVER}
@echo "build server docker image (from alpine)"
rm -rf ${MKFILE_DIR}rootfs/alpine/opt && \
mkdir -p ${MKFILE_DIR}rootfs/alpine/opt/easegress/bin && \
cp ${TARGET_SERVER} ${MKFILE_DIR}rootfs/alpine/opt/easegress/bin && \
cd ${MKFILE_DIR}rootfs/alpine && $(DOCKER) build -t ${DOCKER_REPO_INFO}:server-${RELEASE}_alpine -f ./Dockerfile.server .

build_server_ubuntu: ${TARGET_SERVER}
@echo "build server docker image (from ubuntu)"
rm -rf ${MKFILE_DIR}rootfs/ubuntu/opt && \
mkdir -p ${MKFILE_DIR}rootfs/ubuntu/opt/easegress/bin && \
cp ${TARGET_SERVER} ${MKFILE_DIR}rootfs/ubuntu/opt/easegress/bin && \
cd ${MKFILE_DIR}rootfs/ubuntu && $(DOCKER) build -t ${DOCKER_REPO_INFO}:server-${RELEASE}_ubuntu -f ./Dockerfile.server .
build_docker:
docker build -t megaease/easegress:${RELEASE} -f ./build/package/Dockerfile .

test:
@go list ./{cmd,pkg}/... | grep -v -E 'vendor' | xargs -n1 go test
Expand Down Expand Up @@ -97,11 +75,4 @@ ${TARGET_CLIENT} : ${CLIENT_FILES}
@echo "build client"
cd ${MKFILE_DIR} && \
CGO_ENABLED=0 go build -v -ldflags ${GO_LD_FLAGS} \
-o ${TARGET_CLIENT} ${MKFILE_DIR}cmd/client/main.go

${TARGET_INVENTORY} : ${INVENTORY_FILES}
@echo "build inventory"
cd ${MKFILE_DIR} && \
rm -rf ${TARGET_INVENTORY} && \
mkdir -p ${TARGET_INVENTORY} && \
cp -r ${INVENTORY_FILES} ${TARGET_INVENTORY}
-o ${TARGET_CLIENT} ${MKFILE_DIR}cmd/client/main.go
23 changes: 23 additions & 0 deletions build/package/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:alpine AS builder
RUN apk --no-cache add make git

WORKDIR /opt/easegress
COPY . .

RUN make clean && make build

# ---

FROM alpine:3.13

WORKDIR /opt/easegress

COPY build/package/entrypoint.sh /
COPY --from=builder /opt/easegress/bin/ /opt/easegress/bin/

RUN apk --no-cache add tini && \
chmod +x /entrypoint.sh /opt/easegress/bin/*

ENV PATH /opt/easegress/bin:$PATH

ENTRYPOINT ["/sbin/tini", "--", "/entrypoint.sh"]
13 changes: 13 additions & 0 deletions build/package/Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:3.13

WORKDIR /opt/easegress

ADD egctl easegress-server /opt/easegress/bin/
COPY build/package/entrypoint.sh /

RUN apk --no-cache add tini && \
chmod +x /entrypoint.sh /opt/easegress/bin/*

ENV PATH /opt/easegress/bin:$PATH

ENTRYPOINT ["/sbin/tini", "--", "/entrypoint.sh"]
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/sh

if [ $# -eq 0 ] ; then
set -- "-plugin_python_root_namespace" "-plugin_shell_root_namespace"
fi

if [ "$(echo $1 | head -c 1)" != "-" ] ; then
exec "$@"
else
Expand Down
6 changes: 0 additions & 6 deletions rootfs/alpine/Dockerfile.client

This file was deleted.

12 changes: 0 additions & 12 deletions rootfs/alpine/entrypoint.client.sh

This file was deleted.

12 changes: 0 additions & 12 deletions rootfs/alpine/entrypoint.server.sh

This file was deleted.

7 changes: 0 additions & 7 deletions rootfs/ubuntu/Dockerfile.server

This file was deleted.

0 comments on commit 29e1179

Please sign in to comment.