├── go.mod ├── main.go ├── cloudbuild.yaml └── Dockerfile /go.mod: -------------------------------------------------------------------------------- 1 | module EkoEdyPurwanto/repayment-utility-service 2 | 3 | go 1.21.1 4 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net/http" 7 | "os" 8 | ) 9 | 10 | func main() { 11 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 12 | fmt.Fprintln(w, "repayment-utility-service App V1") 13 | }) 14 | port := os.Getenv("PORT") 15 | if port == "" { 16 | port = "8080" 17 | } 18 | log.Fatal(http.ListenAndServe(":"+port, nil)) 19 | } 20 | -------------------------------------------------------------------------------- /cloudbuild.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | # build the container image 3 | - name: 'gcr.io/cloud-builders/docker' 4 | args: ['build', '-t', 'gcr.io/$PROJECT_ID/repayment-utility-service', '.'] 5 | 6 | # push the container image to container registry 7 | - name: 'gcr.io/cloud-builders/docker' 8 | args: ['push', 'gcr.io/$PROJECT_ID/repayment-utility-service'] 9 | 10 | # deploy the container image to cloud run 11 | - name: 'gcr.io/cloud-builders/gcloud' 12 | args: ['run', 13 | 'deploy', 14 | 'repayment-utility-service', 15 | '--image', 16 | 'gcr.io/$PROJECT_ID/repayment-utility-service', 17 | '--region', 18 | 'us-central1', 19 | '--platform', 20 | 'managed', 21 | '--allow-unauthenticated'] 22 | 23 | # set env vars 24 | env: 25 | - '_USER_SERVICE_URL_=user-service.mekar-test.xyz' 26 | 27 | images: ['gcr.io/$PROJECT_ID/repayment-utility-service'] 28 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | ### Build Stage ### 2 | FROM golang:1.21.1-alpine3.18 AS BUILD 3 | 4 | ### LABEL INSTRUCTION (hanya metadata) ### 5 | LABEL authors="eep" 6 | LABEL company="PT Mekar Investama Sampoerna" reachMe="https://github.com/EchoEdyP" 7 | 8 | # Set the working directory inside the container 9 | WORKDIR /go/src/app 10 | 11 | # Copy the Go modules manifests 12 | COPY go.mod ./ 13 | 14 | ### Copy the source code into the container (build stage) ### 15 | COPY . . 16 | 17 | ### RUN INSTRUCTION (Build Stage) ### 18 | RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o repayment-utility-service ./main.go 19 | 20 | ### Production Stage ### 21 | FROM alpine:3.18 22 | 23 | # Set the working directory inside the container 24 | WORKDIR /app 25 | 26 | # Install curl 27 | RUN apk --no-cache add curl 28 | 29 | # Copy only the necessary files from the build stage 30 | COPY --from=BUILD /go/src/app/repayment-utility-service . 31 | 32 | # Define environment variable for USER_SERVICE_URL 33 | ENV _USER_SERVICE_URL_=user-service.mekar-test.xyz 34 | 35 | ### CMD INSTRUCTION (if container run) ### 36 | CMD ["./repayment-utility-service"] 37 | --------------------------------------------------------------------------------