B: adding deployment things
This commit is contained in:
parent
4c5f29c0b9
commit
6f3ec2375b
|
@ -35,3 +35,5 @@ infra/*_override.tf.json
|
|||
# Ignore CLI configuration files
|
||||
infra/.terraformrc
|
||||
infra/terraform.rc
|
||||
|
||||
secrets/*
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
BASE_URL=us-central1-docker.pkg.dev/pbaxter-infra/capstone-repo
|
||||
FRONTEND_VERSION=$(shell jq -rc ".frontend_version" versions.json)
|
||||
WEBHOOK_VERSION=$(shell jq -rc ".webhook_version" versions.json)
|
||||
|
||||
deploy: deploy-tf deploy-ui deploy-service
|
||||
|
||||
deploy-tf:
|
||||
cd infra; make deploy
|
||||
|
||||
deploy-ui: build-ui
|
||||
docker push $(BASE_URL)/frontend-service:latest
|
||||
|
||||
deploy-service: build-service
|
||||
docker push $(BASE_URL)/webhook-service:latest
|
||||
|
||||
build: build-ui build-service
|
||||
|
||||
build-ui:
|
||||
docker build -f ./docker/ui.dockerfile . -t frontend-service:latest
|
||||
docker build -f ./docker/ui.dockerfile . -t frontend-service:$(FRONTEND_VERSION)
|
||||
docker tag frontend-service:latest $(BASE_URL)/frontend-service:latest
|
||||
docker tag frontend-service:$(FRONTEND_VERSION) $(BASE_URL)/frontend-service:$(FRONTEND_VERSION)
|
||||
|
||||
build-service:
|
||||
docker build -f ./docker/service.dockerfile . -t webhook-service:latest
|
||||
docker build -f ./docker/service.dockerfile . -t webhook-service:$(WEBHOOK_VERSION)
|
||||
docker tag webhook-service:latest $(BASE_URL)/webhook-service:latest
|
||||
docker tag webhook-service:$(FRONTEND_VERSION) $(BASE_URL)/webhook-service:$(WEBHOOK_VERSION)
|
||||
|
||||
image: SHELL := /bin/bash
|
||||
image:
|
||||
[[ -d "/tmp/capstone" ]] || mkdir /tmp/capstone
|
||||
cp -R infra/ /tmp/capstone/
|
||||
cp -R service/ /tmp/capstone/
|
||||
cp -R ui/ /tmp/capstone/
|
||||
rm -rf /tmp/capstone/ui/templates/*_templ.go
|
||||
codevis -i /tmp/capstone --whitelist-extension go,hcl,tf,templ -o ./out.png
|
||||
rm -rf /tmp/capstone/*
|
32
Makefile
32
Makefile
|
@ -1,8 +1,34 @@
|
|||
deploy:
|
||||
cd service; make deploy
|
||||
cd ui; make deploy
|
||||
BASE_URL=us-central1-docker.pkg.dev/pbaxter-infra/capstone-repo
|
||||
FRONTEND_VERSION=$(shell jq -rc ".frontend_version" versions.json)
|
||||
WEBHOOK_VERSION=$(shell jq -rc ".webhook_version" versions.json)
|
||||
|
||||
deploy: deploy-ui deploy-service deploy-tf
|
||||
|
||||
deploy-tf:
|
||||
cd infra; make deploy
|
||||
|
||||
deploy-ui: build-ui
|
||||
docker push $(BASE_URL)/frontend-service:latest
|
||||
docker push $(BASE_URL)/frontend-service:$(FRONTEND_VERSION)
|
||||
|
||||
deploy-service: build-service
|
||||
docker push $(BASE_URL)/webhook-service:latest
|
||||
docker push $(BASE_URL)/webhook-service:$(WEBHOOK_VERSION)
|
||||
|
||||
build: build-ui build-service
|
||||
|
||||
build-ui:
|
||||
docker build -f ./docker/ui.dockerfile . -t frontend-service:latest
|
||||
docker build -f ./docker/ui.dockerfile . -t frontend-service:$(FRONTEND_VERSION)
|
||||
docker tag frontend-service:latest $(BASE_URL)/frontend-service:latest
|
||||
docker tag frontend-service:$(FRONTEND_VERSION) $(BASE_URL)/frontend-service:$(FRONTEND_VERSION)
|
||||
|
||||
build-service:
|
||||
docker build -f ./docker/service.dockerfile . -t webhook-service:latest
|
||||
docker build -f ./docker/service.dockerfile . -t webhook-service:$(WEBHOOK_VERSION)
|
||||
docker tag webhook-service:latest $(BASE_URL)/webhook-service:latest
|
||||
docker tag webhook-service:$(WEBHOOK_VERSION) $(BASE_URL)/webhook-service:$(WEBHOOK_VERSION)
|
||||
|
||||
image: SHELL := /bin/bash
|
||||
image:
|
||||
[[ -d "/tmp/capstone" ]] || mkdir /tmp/capstone
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
from golang:1.21-alpine as builder
|
||||
|
||||
WORKDIR /build/service
|
||||
|
||||
COPY service/go.mod service/go.sum ./
|
||||
COPY ./ui ../ui
|
||||
COPY ./libs ../libs
|
||||
|
||||
RUN go mod download
|
||||
|
||||
COPY ./service .
|
||||
|
||||
RUN go build -o main
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
COPY --from=builder /build/service/main /bin/main
|
||||
RUN mkdir -p /etc/capstone
|
||||
COPY secrets/config.yaml /etc/capstone
|
||||
|
||||
EXPOSE "8080"
|
||||
|
||||
ENTRYPOINT ["/bin/main"]
|
|
@ -0,0 +1,40 @@
|
|||
#Build Go stuff
|
||||
FROM golang:1.21-alpine AS builder
|
||||
|
||||
RUN go install github.com/a-h/templ/cmd/templ@latest
|
||||
|
||||
WORKDIR /build/ui
|
||||
|
||||
#Setup libs
|
||||
COPY ui/go.mod ui/go.sum ./
|
||||
COPY ./service ../service
|
||||
COPY ./libs ../libs
|
||||
|
||||
RUN go mod download
|
||||
|
||||
COPY ui/ .
|
||||
|
||||
RUN rm **/*_templ.go; templ generate -path ./templates
|
||||
RUN go build -o main
|
||||
|
||||
#Build NPM stuff
|
||||
FROM node:18-alpine AS node-builder
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
COPY ui/ .
|
||||
|
||||
RUN npm install
|
||||
RUN npx tailwindcss -i static/index.css -o dist/output.css
|
||||
|
||||
#Final Contianer
|
||||
FROM alpine:latest
|
||||
|
||||
COPY --from=node-builder /build/dist /bin/dist
|
||||
COPY --from=builder /build/ui/main /bin/main
|
||||
RUN mkdir -p /etc/capstone
|
||||
COPY secrets/config.yaml /etc/capstone
|
||||
|
||||
EXPOSE "8080"
|
||||
|
||||
ENTRYPOINT ["/bin/main"]
|
|
@ -1,2 +1,8 @@
|
|||
FRONTEND_VERSION=$(shell jq -rc ".frontend_version" ../versions.json)
|
||||
WEBHOOK_VERSION=$(shell jq -rc ".webhook_version" ../versions.json)
|
||||
|
||||
deploy: SHELL := /bin/bash
|
||||
deploy:
|
||||
sed -i -Ee "s/(webhook_service_tag = \").*(\")/\1$(WEBHOOK_VERSION)\2/g" terraform.tfvars
|
||||
sed -i -Ee "s/(frontend_service_tag = \").*(\")/\1$(FRONTEND_VERSION)\2/g" terraform.tfvars
|
||||
tofu apply
|
||||
|
|
|
@ -16,6 +16,16 @@ variable "project_region" {
|
|||
type = string
|
||||
}
|
||||
|
||||
variable "webhook_service_tag" {
|
||||
description = "Tag for the webhook service collector image"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "frontend_service_tag" {
|
||||
description = "Tag for the frontend service collector image"
|
||||
type = string
|
||||
}
|
||||
|
||||
provider "google" {
|
||||
project = var.project_id
|
||||
}
|
||||
|
@ -58,7 +68,7 @@ resource "google_cloud_run_v2_service" "webhook_service_cr" {
|
|||
|
||||
template {
|
||||
containers {
|
||||
image = "${var.project_region}-docker.pkg.dev/${var.project_id}/${google_artifact_registry_repository.capstone_repo.name}/webhook-service:latest"
|
||||
image = "${var.project_region}-docker.pkg.dev/${var.project_id}/${google_artifact_registry_repository.capstone_repo.name}/webhook-service:${var.webhook_service_tag}"
|
||||
}
|
||||
vpc_access{
|
||||
network_interfaces {
|
||||
|
@ -87,7 +97,7 @@ resource "google_cloud_run_v2_service" "frontend_service_cr" {
|
|||
|
||||
template {
|
||||
containers {
|
||||
image = "${var.project_region}-docker.pkg.dev/${var.project_id}/${google_artifact_registry_repository.capstone_repo.name}/frontend-service:latest"
|
||||
image = "${var.project_region}-docker.pkg.dev/${var.project_id}/${google_artifact_registry_repository.capstone_repo.name}/frontend-service:${var.frontend_service_tag}"
|
||||
}
|
||||
vpc_access{
|
||||
network_interfaces {
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
from golang:1.21-alpine as builder
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
RUN go mod download
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN go build -o main
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
COPY --from=builder /build/main /bin/main
|
||||
|
||||
EXPOSE "8080"
|
||||
|
||||
ENTRYPOINT ["/bin/main"]
|
|
@ -2,25 +2,28 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/config"
|
||||
"git.preston-baxter.com/Preston_PLB/capstone/webhook-service/controllers"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
config.Init()
|
||||
r := gin.Default()
|
||||
r.POST("/webhook", func(c *gin.Context) {
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("captured: %s\n", string(body))
|
||||
controllers.BuildRouter(r)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "pong",
|
||||
})
|
||||
})
|
||||
r.Run("0.0.0.0:8081") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
|
||||
var addr string
|
||||
if port := os.Getenv("PORT"); port != "" {
|
||||
addr = fmt.Sprintf("0.0.0.0:%s", port)
|
||||
} else {
|
||||
addr = "0.0.0.0:8008"
|
||||
}
|
||||
|
||||
err := r.Run(addr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/db/models"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
from golang:1.21-alpine as builder
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
RUN go mod download
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN go build -o main
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
COPY --from=builder /build/main /bin/main
|
||||
|
||||
EXPOSE "8080"
|
||||
|
||||
ENTRYPOINT ["/bin/main"]
|
|
@ -8,7 +8,6 @@ local-build:
|
|||
local-run: local-build
|
||||
./tmp/main
|
||||
|
||||
|
||||
infra-clean:
|
||||
cd docker; docker compose down
|
||||
|
||||
|
@ -17,7 +16,7 @@ infra:
|
|||
|
||||
|
||||
build:
|
||||
docker build . -t frontend-service:latest
|
||||
docker build -f ../docker/ui.dockerfile . -t frontend-service:latest
|
||||
docker tag frontend-service:latest $(BASE_URL)/frontend-service:latest
|
||||
|
||||
deploy: build
|
||||
|
|
15
ui/main.go
15
ui/main.go
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/config"
|
||||
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/controllers"
|
||||
|
@ -15,8 +15,15 @@ func main() {
|
|||
|
||||
controllers.BuildRouter(r)
|
||||
|
||||
err := http.ListenAndServeTLS(":8080", "tls.crt", "tls.key", r)
|
||||
var addr string
|
||||
if port := os.Getenv("PORT"); port != "" {
|
||||
addr = fmt.Sprintf("0.0.0.0:%s", port)
|
||||
} else {
|
||||
addr = "0.0.0.0:8008"
|
||||
}
|
||||
|
||||
err := r.Run(addr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"webhook_version": "0.0.3",
|
||||
"frontend_version": "0.0.3"
|
||||
}
|
Loading…
Reference in New Issue