Skip to content

Commit d93cb24

Browse files
committed
service fixes
1 parent 95a8eae commit d93cb24

File tree

6 files changed

+27
-55
lines changed

6 files changed

+27
-55
lines changed

Makefile

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,72 +26,30 @@ help: ## Show help message
2626

2727
build-users: ## Builds and pushes the users service image
2828
@echo "${PROMPT_COLOR}Building users image'...${PROMPT_NC}"
29-
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_USERS_SERVICE_NAME)-amd64 --push --file build/$(MS_USERS_SERVICE_NAME).Dockerfile .
30-
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_USERS_SERVICE_NAME)-arm64 --push --file build/$(MS_USERS_SERVICE_NAME).Dockerfile .
29+
docker buildx build --platform linux/amd64,linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_USERS_SERVICE_NAME) --push --file build/$(MS_USERS_SERVICE_NAME).Dockerfile .
3130

3231
build-cart: ## Builds and pushes the cart service image
3332
@echo "${PROMPT_COLOR}Building cart image'...${PROMPT_NC}"
34-
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_CART_SERVICE_NAME)-amd64 --push --file build/$(MS_CART_SERVICE_NAME).Dockerfile .
35-
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_CART_SERVICE_NAME)-arm64 --push --file build/$(MS_CART_SERVICE_NAME).Dockerfile .
33+
docker buildx build --platform linux/amd64,linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_CART_SERVICE_NAME) --push --file build/$(MS_CART_SERVICE_NAME).Dockerfile .
3634

3735
build-checkout: ## Builds and pushes the checkout service image
3836
@echo "${PROMPT_COLOR}Building checkout image'...${PROMPT_NC}"
39-
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_CHECKOUT_SERVICE_NAME)-amd64 --push --file build/$(MS_CHECKOUT_SERVICE_NAME).Dockerfile .
40-
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_CHECKOUT_SERVICE_NAME)-arm64 --push --file build/$(MS_CHECKOUT_SERVICE_NAME).Dockerfile .
37+
docker buildx build --platform linux/amd64,linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_CHECKOUT_SERVICE_NAME) --push --file build/$(MS_CHECKOUT_SERVICE_NAME).Dockerfile .
4138

4239
build-frontend: ## Builds and pushes the frontend service image
4340
@echo "${PROMPT_COLOR}Building frontend image'...${PROMPT_NC}"
44-
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_FRONTEND_SERVICE_NAME)-amd64 --push --file build/$(MS_FRONTEND_SERVICE_NAME).Dockerfile .
45-
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_FRONTEND_SERVICE_NAME)-arm64 --push --file build/$(MS_FRONTEND_SERVICE_NAME).Dockerfile .
41+
docker buildx build --platform linux/amd64,linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_FRONTEND_SERVICE_NAME) --push --file build/$(MS_FRONTEND_SERVICE_NAME).Dockerfile .
4642

4743
build-newsletter: ## Builds and pushes the newsletter service image
4844
@echo "${PROMPT_COLOR}Building newsletter image'...${PROMPT_NC}"
49-
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_NEWSLETTER_SERVICE_NAME)-amd64 --push --file build/$(MS_NEWSLETTER_SERVICE_NAME).Dockerfile .
50-
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_NEWSLETTER_SERVICE_NAME)-arm64 --push --file build/$(MS_NEWSLETTER_SERVICE_NAME).Dockerfile .
45+
docker buildx build --platform linux/amd64,linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_NEWSLETTER_SERVICE_NAME) --push --file build/$(MS_NEWSLETTER_SERVICE_NAME).Dockerfile .
5146

5247
build-products: ## Builds and pushes the products service image
5348
@echo "${PROMPT_COLOR}Building products image'...${PROMPT_NC}"
54-
docker buildx build --platform linux/amd64 -t $(MS_IMAGE_REGISTRY):$(MS_PRODUCTS_SERVICE_NAME)-amd64 --push --file build/$(MS_PRODUCTS_SERVICE_NAME).Dockerfile .
55-
docker buildx build --platform linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_PRODUCTS_SERVICE_NAME)-arm64 --push --file build/$(MS_PRODUCTS_SERVICE_NAME).Dockerfile .
49+
docker buildx build --platform linux/amd64,linux/arm64 -t $(MS_IMAGE_REGISTRY):$(MS_PRODUCTS_SERVICE_NAME) --push --file build/$(MS_PRODUCTS_SERVICE_NAME).Dockerfile .
5650

5751
build-images: build-users build-cart build-checkout build-frontend build-newsletter build-products ## Build and push all images
5852

59-
# Combine arch images
60-
61-
tag-users: ## Tag the users service images
62-
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_USERS_SERVICE_NAME) \
63-
$(MS_IMAGE_REGISTRY):$(MS_USERS_SERVICE_NAME)-amd64 \
64-
$(MS_IMAGE_REGISTRY):$(MS_USERS_SERVICE_NAME)-arm64
65-
66-
tag-cart: ## Tag the cart service images
67-
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_CART_SERVICE_NAME) \
68-
$(MS_IMAGE_REGISTRY):$(MS_CART_SERVICE_NAME)-amd64 \
69-
$(MS_IMAGE_REGISTRY):$(MS_CART_SERVICE_NAME)-arm64
70-
71-
tag-checkout: ## Tag the checkout service images
72-
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_CHECKOUT_SERVICE_NAME) \
73-
$(MS_IMAGE_REGISTRY):$(MS_CHECKOUT_SERVICE_NAME)-amd64 \
74-
$(MS_IMAGE_REGISTRY):$(MS_CHECKOUT_SERVICE_NAME)-arm64
75-
76-
tag-frontend: ## Tag the frontend service images
77-
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_FRONTEND_SERVICE_NAME) \
78-
$(MS_IMAGE_REGISTRY):$(MS_FRONTEND_SERVICE_NAME)-amd64 \
79-
$(MS_IMAGE_REGISTRY):$(MS_FRONTEND_SERVICE_NAME)-arm64
80-
81-
tag-newsletter: ## Tag the newsletter service images
82-
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_NEWSLETTER_SERVICE_NAME) \
83-
$(MS_IMAGE_REGISTRY):$(MS_NEWSLETTER_SERVICE_NAME)-amd64 \
84-
$(MS_IMAGE_REGISTRY):$(MS_NEWSLETTER_SERVICE_NAME)-arm64
85-
86-
tag-products: ## Tag the products service images
87-
docker buildx imagetools create -t $(MS_IMAGE_REGISTRY):$(MS_PRODUCTS_SERVICE_NAME) \
88-
$(MS_IMAGE_REGISTRY):$(MS_PRODUCTS_SERVICE_NAME)-amd64 \
89-
$(MS_IMAGE_REGISTRY):$(MS_PRODUCTS_SERVICE_NAME)-arm64
90-
91-
tag-images: tag-users tag-cart tag-checkout tag-frontend tag-newsletter tag-products ## Tag all images
92-
93-
update-images: build-images tag-images ## Build and tag all images
94-
9553
install-otterside: ## Installs Otterside in the kubernetes cluster
9654
helm --kubeconfig=$(KUBECONFIG_PATH) dep up $(HELM_CHART_PATH); \
9755
helm --kubeconfig=$(KUBECONFIG_PATH) upgrade --install otterside $(HELM_CHART_PATH) -n $(OTTERSIDE_NAMESPACE) --create-namespace

helm/values.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ services:
4040
tag: products
4141
port: 7002
4242
env:
43-
STORAGE_ENABLED: "false"
44-
STORAGE_BUCKET_NAME: bucket-name
43+
STORAGE_ENABLED: true
44+
STORAGE_REGION: us-east-1
45+
STORAGE_BUCKET_NAME: otterside
4546
STORAGE_OBJECT_KEY: products.json
4647

4748
newsletter-service:

services/frontend/routes/newsletter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111

1212

1313
@router.post("/subscribe", tags=["newsletter"], response_class=HTMLResponse)
14-
async def products(email: str = Form(...)):
14+
async def subscribe(email: str = Form(...)):
1515
api_resp = requests.post(url=f'{NEWSLETTER_SERVICE_API}/subscribe', verify=False, json={
1616
"email": email
1717
})
1818
if api_resp.status_code == 201:
1919
return HTMLResponse(status_code=200, content="Successfully subscribed to newsletter!")
2020

21+
print(f"Could not subscribe. Error: {api_resp.text}")
2122
return HTMLResponse(
2223
status_code=api_resp.status_code,
2324
content="Could not subscribe. Please try again later."

services/frontend/routes/products.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ async def products(request: Request):
2222
}
2323
)
2424

25+
print(f"Could not load products. Error: {api_resp.text}")
2526
return HTMLResponse(status_code=500, content="Could not load products. Please try again later.")

services/newsletter/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ app.post('/subscribe', async (req, res) => {
7373
if (error.name === 'SequelizeUniqueConstraintError') {
7474
return res.status(201).json({ message: 'Subscribed successfully' });
7575
}
76+
77+
console.log(error)
7678
return res.status(500).json({ error: 'Failed to subscribe' });
7779
}
7880
});

services/products/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ type Product struct {
3030
var products []Product
3131
var mu sync.Mutex // Mutex for thread-safe access to products
3232

33-
var BucketEnabled = getEnv("STORAGE_ENABLED", "false")
34-
var BucketName = getEnv("STORAGE_BUCKET_NAME", "bucket-name")
33+
var BucketEnabled = getEnv("STORAGE_ENABLED", "true")
34+
var BucketRegion = getEnv("STORAGE_REGION", "us-east-1")
35+
var BucketName = getEnv("STORAGE_BUCKET_NAME", "otterside")
3536
var ObjectKey = getEnv("STORAGE_OBJECT_KEY", "products.json")
3637

3738
func getEnv(key, fallback string) string {
@@ -50,6 +51,8 @@ func loadProducts(client *s3.Client) {
5051
var err error
5152

5253
if BucketEnabled == "true" {
54+
log.Printf("Loading products from S3 bucket: %s\n", BucketName)
55+
5356
input := &s3.GetObjectInput{
5457
Bucket: aws.String(BucketName),
5558
Key: aws.String(ObjectKey),
@@ -68,7 +71,9 @@ func loadProducts(client *s3.Client) {
6871
return
6972
}
7073
} else {
71-
data, err = ioutil.ReadFile("products.json")
74+
log.Printf("Loading products from filesystem: %s\n", ObjectKey)
75+
76+
data, err = ioutil.ReadFile(ObjectKey)
7277
if err != nil {
7378
log.Fatalf("Failed to read products.json: %v", err)
7479
}
@@ -118,7 +123,11 @@ func getProductByID(w http.ResponseWriter, r *http.Request) {
118123

119124
func main() {
120125
// Initialize AWS SDK for S3
121-
cfg, err := config.LoadDefaultConfig(context.TODO())
126+
cfg, err := config.LoadDefaultConfig(
127+
context.TODO(),
128+
config.WithRegion(BucketRegion),
129+
config.WithCredentialsProvider(aws.AnonymousCredentials{}),
130+
)
122131
if err != nil {
123132
log.Fatalf("Unable to load AWS SDK config: %v", err)
124133
}

0 commit comments

Comments
 (0)