feat: init make file and docker file

This commit is contained in:
daniel.w 2024-08-20 18:05:39 +08:00
parent c1188a8308
commit dd872b7abf
6 changed files with 47 additions and 33 deletions

View File

@ -1,6 +1,4 @@
GO_CTL_NAME=goctl
# go-zero 生成風格
GO_ZERO_STYLE=go_zero
@ -8,6 +6,9 @@ GO ?= go
GOFMT ?= gofmt "-s"
GOFILES := $(shell find . -name "*.go")
LDFLAGS := -s -w
VERSION="v1.0.3"
DOCKER_REPO="igs170911/notification"
.PHONY: test
test: # 進行測試
@ -35,3 +36,13 @@ gen-clean: # 建立 rpc code
rm -rf go.sum
rm -rf service.go
@echo "Generate core-api files successfully"
.PHONY: run-docker
run-docker: # 建立 rpc code
docker run --platform=linux/arm64/v8 -p 8080:8080 $(DOCKER_REPO):$(VERSION)
.PHONY: build-docker
build-docker:
cp ./build/Dockerfile Dockerfile
docker buildx build -t $(DOCKER_REPO):$(VERSION) --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/ed_25519)" .
rm -rf Dockerfile

View File

@ -2,46 +2,46 @@
# BUILDER #
###########
FROM golang:1.20 as builder
FROM golang:1.22.3 as builder
ARG VERSION
ARG BUILT
ARG GIT_COMMIT
ARG SSH_PRV_KEY
# private go packages
ENV GOPRIVATE=code.30cm.net
ENV FLAG="-s -w -X main.Version=${VERSION} -X main.Built=${BUILT} -X main.GitCommit=${GIT_COMMIT}"
WORKDIR /app
COPY . .
RUN apt-get update && \
apt-get install git
WORKDIR /app
# Make the root foler for our ssh
RUN mkdir -p /root/.ssh && \
chmod 0700 /root/.ssh && \
ssh-keyscan git.30cm.net > /root/.ssh/known_hosts && \
echo "$SSH_PRV_KEY" > /root/.ssh/id_rsa && \
chmod 600 /root/.ssh/id_rsa
COPY . .
# Download public key for yt.com
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan yt.com >> ~/.ssh/known_hosts
# Forces the usage of git and ssh key fwded by ssh-agent for yt.com git repos
RUN git config --global url."git@yt.com:".insteadOf "https://yt.com"
# private go packages
ENV GOPRIVATE=yt.com
RUN --mount=type=ssh go mod download
ENV FLAG="-s -w -X main.Version=${VERSION} -X main.Built=${BUILT} -X main.GitCommit=${GIT_COMMIT}"
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags "$FLAG" \
-o /permission-server ./cmd/permission
#########
# FINAL #
#########
FROM oraclelinux:9-slim AS final
-o service
##########
## FINAL #
##########
#
FROM gcr.io/distroless/static-debian11
WORKDIR /app
COPY --from=builder /permission-server /app/permission-server
COPY --from=builder /app/configs/config-example.yaml /app/config.yaml
COPY --from=builder /app/configs/rbac_model.conf /app/rbac_model.conf
CMD ["/app/permission-server"]
COPY --from=builder /app/service /app/service
COPY --from=builder /app/etc/service.yaml /app/etc/service.yaml
EXPOSE 8080
CMD ["/app/service"]

View File

@ -2,5 +2,5 @@ Name: service.rpc
ListenOn: 0.0.0.0:8080
Etcd:
Hosts:
- 127.0.0.1:2379
- docker-etcd.digimon.orb.local:2379
Key: service.rpc

1
go.mod
View File

@ -3,6 +3,7 @@ module app-cloudep-notification-service
go 1.22.3
require (
code.30cm.net/digimon/library-go/errors v1.0.0
github.com/zeromicro/go-zero v1.7.0
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2

View File

@ -2,10 +2,12 @@ package senderservicelogic
import (
"context"
"fmt"
"app-cloudep-notification-service/gen_result/pb/notification"
"app-cloudep-notification-service/internal/svc"
ers "code.30cm.net/digimon/library-go/errors"
"github.com/zeromicro/go-zero/core/logx"
)
@ -23,9 +25,9 @@ func NewSendMailByTemplateIdLogic(ctx context.Context, svcCtx *svc.ServiceContex
}
}
// SendMailByTemplateID 寄送模板信件
// SendMailByTemplateId 寄送模板信件
func (l *SendMailByTemplateIdLogic) SendMailByTemplateId(in *notification.SendByTemplateIDReq) (*notification.OKResp, error) {
// todo: add your logic here and delete this line
fmt.Println(ers.ResourceNotFound("testing"))
return &notification.OKResp{}, nil
}

View File

@ -7,7 +7,7 @@ import (
"context"
"app-cloudep-notification-service/gen_result/pb/notification"
"app-cloudep-notification-service/internal/logic/senderservice"
senderservicelogic "app-cloudep-notification-service/internal/logic/senderservice"
"app-cloudep-notification-service/internal/svc"
)