From 80de4388008a691d9d5dbbbd1af7e834c5fde773 Mon Sep 17 00:00:00 2001 From: dustoair <107600816+dustoair@users.noreply.github.com> Date: Fri, 22 Jul 2022 17:19:06 +0800 Subject: [PATCH] add k8s config --- Dockerfile | 27 +++++++++++++++++++++++++++ README.md | 18 +++++++++++++++++- ip_test.go | 18 ++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 ip_test.go diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e4668a8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +################################################################################ +## MAIN STAGE ## +################################################################################ +# Copy the manager into the distroless image. +#FROM scratch +#FROM hub.sre.ink/base/distroless-static:nonroot-20210710 +#FROM mirror.ccs.tencentyun.com/library/alpine:3.13 +FROM alpine:3.15.0 +#FROM hub.sre.ink/base/alpine:3.15.0 +#FROM centos:7.9.2009 +LABEL Description="sre ip region service" +MAINTAINER sre +#RUN echo 'https://mirrors.cloud.tencent.com/alpine/v3.13/main' > /etc/apk/repositories \ +# && echo 'https://mirrors.cloud.tencent.com/alpine/v3.13/community' >>/etc/apk/repositories \ +# && apk update && apk add tzdata && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ +# && echo "Asia/Shanghai" > /etc/timezone +RUN apk update && apk add tzdata && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo "Asia/Shanghai" > /etc/timezone + +WORKDIR /app +ADD ipregion.bin /app/ipregion.bin +COPY ip2region.db /app/ip2region.db +RUN chmod -R 777 /app + +#USER nonroot:nonroot +EXPOSE 8080 +ENTRYPOINT ["/app/ipregion.bin"] \ No newline at end of file diff --git a/README.md b/README.md index 37c9d94..4eb66a7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,19 @@ # ip地址归属地查询 http://127.0.0.1:8080?address=git.sre.ink +## build arm64 on oracle k8s +```bash +cd /root +rm -rf IPRegion +git clone https://git.sre.ink/go/IPRegion.git +cd IPRegion +CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go mod tidy +CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -v -a -o ipregion.bin main.go +docker build -t sre/ipregion:arm64 . +kubectl rollout restart deployment -n sre ginbase +``` + + + ## bench ```bash goos: windows @@ -13,4 +27,6 @@ BenchmarkMemorySearch-16 5435004 220.3 ns/op BenchmarkBinarySearch BenchmarkBinarySearch-16 34378 34766 ns/op PASS -``` \ No newline at end of file +``` + + diff --git a/ip_test.go b/ip_test.go new file mode 100644 index 0000000..029c089 --- /dev/null +++ b/ip_test.go @@ -0,0 +1,18 @@ +package main + +import ( + "IPRegion/global" + "IPRegion/ip2region" + "encoding/json" + "fmt" + "testing" +) + +func TestIpInfo(tt *testing.T) { + address := "114.114.114.114" + var ipInfo ip2region.IpInfo + ipInfo, _ = GetIPInfo(address, global.SearchType) + res, _ := json.Marshal(ipInfo) + fmt.Println(string(res)) + +}