Skip to content

Commit

Permalink
*: improve docker scripts (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Oct 8, 2022
1 parent e255b6b commit c46acb9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 65 deletions.
1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.git/
**/bin
**/test
**/*.iml
**/.idea
**/*.swp
**/.DS_Store
**/vendor
**/work
**/.vscode/
**/.cover*
2 changes: 1 addition & 1 deletion .github/workflows/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
path: |
${{ env.GOCACHE }}
${{ env.GOMODCACHE }}
key: ${{ runner.os }}-go-${{ inputs.ref }}
key: ${{ runner.os }}-go-${{ inputs.target == "cache" && github.run_id || hashFiles('**/go.sum')}}
restore-keys: |
${{ runner.os }}-go-
- name: make ${{ inputs.target }}
Expand Down
18 changes: 8 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

PROJECTNAME = $(shell basename "$(PWD)")
GOBIN := $(shell pwd)/bin
DOCKERFLAG ?=
RELEASE ?=
ifneq ($(RELEASE), "")
DOCKERFLAG ?= --squash
endif
DEBUG ?=
DOCKERPREFIX ?=
BUILD_TAGS ?=
LDFLAGS ?=
DEBUG ?=
BUILDFLAGS := $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -tags '${BUILD_TAGS}'
ifeq ("$(WITH_RACE)", "1")
ifneq ("$(DEBUG)", "")
BUILDFLAGS += -race
endif
IMAGE_TAG ?= latest
EXECUTABLE_TARGETS := $(patsubst cmd/%,cmd_%,$(wildcard cmd/*))

.PHONY: cmd_% test lint docker golangci-lint gocovmerge
.PHONY: cmd_% test lint docker docker-release golangci-lint gocovmerge

default: cmd

Expand Down Expand Up @@ -64,4 +59,7 @@ test: gocovmerge
go tool cover -html=.cover -o .cover.html

docker:
docker build $(DOCKERFLAG) -t "tiproxy:${IMAGE_TAG}" --build-arg='GOPROXY=$(shell go env GOPROXY),BUILDFLAGS=$(BUILDFLAGS),' -f docker/Dockerfile .
docker build -t "$(DOCKERPREFIX)tiproxy:$(IMAGE_TAG)" --build-arg 'GOPROXY=$(shell go env GOPROXY),BUILDFLAGS=$(BUILDFLAGS),' -f docker/Dockerfile .

docker-release:
docker buildx build --platform linux/amd64,linux/arm64 --push -t "$(DOCKERPREFIX)tiproxy:$(IMAGE_TAG)" --build-arg 'GOPROXY=$(shell go env GOPROXY),BUILDFLAGS=$(BUILDFLAGS),' -f docker/Dockerfile .
12 changes: 3 additions & 9 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ EXPOSE 3080
EXPOSE 3081
EXPOSE 6000

ADD cmd proxy/cmd
ADD lib proxy/lib
ADD pkg proxy/pkg
ADD conf proxy/conf
ADD go.* docker/apk-fastest-mirror.sh Makefile proxy/
RUN sh ./proxy/apk-fastest-mirror.sh
RUN apk add --no-cache --progress git make go
ADD . https://raw.githubusercontent.com/njhallett/apk-fastest-mirror/main/apk-fastest-mirror.sh /proxy
RUN sh ./proxy/apk-fastest-mirror.sh -t 50 && apk add --no-cache --progress git make go
ARG BUILDFLAGS
ARG GOPROXY
RUN export BUILDFLAGS=${BUILDFLAGS} && export GOPROXY=${GOPROXY} && cd proxy && make cmd && cp bin/* /bin/ && cp -a conf /etc/proxy && cd .. && rm -rf proxy
RUN rm -rf $(go env GOMODCACHE GOCACHE) && apk del git make go
RUN export BUILDFLAGS=${BUILDFLAGS} && export GOPROXY=${GOPROXY} && cd proxy && make cmd && cp bin/* /bin/ && cp -a conf /etc/proxy && cd .. && rm -rf proxy && rm -rf $(go env GOMODCACHE GOCACHE GOPATH) && apk del git make go
ENTRYPOINT ["/bin/tiproxy", "-conf", "/etc/proxy/proxy.yaml"]
44 changes: 0 additions & 44 deletions docker/apk-fastest-mirror.sh

This file was deleted.

0 comments on commit c46acb9

Please sign in to comment.