Skip to content

Commit 4da736a

Browse files
committed
add teraform and deploy script from Sathvik
Signed-off-by: Luke Roy <[email protected]>
1 parent d406e75 commit 4da736a

File tree

12 files changed

+128
-11
lines changed

12 files changed

+128
-11
lines changed

fotobox/cos-setup/main.tf

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# create a cos instance
2+
resource "ibm_resource_instance" "cos_instance" {
3+
name = "cos-instance"
4+
resource_group_id = var.resource_group
5+
plan = "standard"
6+
service = "cloud-object-storage"
7+
location = "global"
8+
}
9+
10+
# create cos-credentials for cos access
11+
resource "ibm_resource_key" "cos-credentials" {
12+
name = "cos-credentials"
13+
resource_instance_id = ibm_resource_instance.cos_instance.id
14+
parameters = {"HMAC" = true}
15+
}
16+
17+
locals {
18+
resource_credentials =jsondecode(ibm_resource_key.cos-credentials.credentials_json)
19+
}
20+
21+
# create cos-but to upload
22+
resource "ibm_cos_bucket" "cos_bucket" {
23+
bucket_name = "fotobox-bucket"
24+
resource_instance_id = ibm_resource_instance.cos_instance.id
25+
region_location = "us-south"
26+
storage_class = "smart"
27+
}
28+
29+
# create code engine project
30+
# set region at provider
31+
resource "ibm_code_engine_project" "ce-fotobox-project" {
32+
name = "codeengine-fotobox-project"
33+
resource_group_id = var.resource_group
34+
}
35+
36+
# create secret in project
37+
38+
resource "ibm_code_engine_secret" "fotobox-secret" {
39+
project_id = ibm_code_engine_project.ce-fotobox-project.id
40+
name = "fotobox-secret"
41+
format = "generic"
42+
43+
data = {
44+
"apikey" = local.resource_credentials.apikey
45+
}
46+
}
47+
48+
resource "ibm_code_engine_secret" "registry_secret" {
49+
project_id = ibm_code_engine_project.ce-fotobox-project.id
50+
name = "container-registry-secret"
51+
format = "registry"
52+
data = {
53+
"username" = "iamapikey" # Use 'iamapikey' as username for IBM Cloud
54+
"password" = var.icr_secret
55+
"server" = "us.icr.io" # Change if using a different registry
56+
}
57+
}
58+
59+
# create config map in project
60+
61+
resource "ibm_code_engine_config_map" "fotobox-config" {
62+
name = "fotobox-config"
63+
project_id = ibm_code_engine_project.ce-fotobox-project.id
64+
data = {
65+
"bucket" = ibm_cos_bucket.cos_bucket.bucket_name
66+
"endpointURL" = ibm_cos_bucket.cos_bucket.s3_endpoint_private
67+
"imageprefix" = "my-event-"
68+
"password" = "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"
69+
"region" = ibm_cos_bucket.cos_bucket.region_location
70+
"resource_instance_id" = local.resource_credentials.resource_instance_id
71+
}
72+
}

fotobox/cos-setup/provider.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "ibm" {
2+
ibmcloud_api_key = var.apikey
3+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource_group = "<resource_group>"
2+
3+
icr_secret = "<icr_secret>"
4+
5+
apikey = "<apikey>"

fotobox/cos-setup/variables.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variable "resource_group" {}
2+
variable "icr_secret" {}
3+
variable "apikey" {}

fotobox/cos-setup/versions.tf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
ibm = {
4+
source = "IBM-Cloud/ibm"
5+
version = "1.76.2"
6+
}
7+
}
8+
}

fotobox/download-app/pkg/cos.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import (
1717
var (
1818
apiKey = os.Getenv("apikey")
1919
serviceInstanceID = os.Getenv("resource_instance_id")
20+
region = os.Getenv("region") // "eu-de"
21+
endpointURL = os.Getenv("endpointURL") // "https://s3.direct.eu-de.cloud-object-storage.appdomain.cloud"
2022
authEndpoint = "https://iam.cloud.ibm.com/identity/token"
21-
endpointURL = "https://s3.direct.eu-de.cloud-object-storage.appdomain.cloud"
22-
bucketName = aws.String(os.Getenv("bucket"))
23-
region = "eu-de"
23+
bucketName = aws.String(os.Getenv("bucket"))
2424
)
2525

2626
const (

fotobox/frontend-app/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=linux/amd64 node:23 as build
1+
FROM --platform=linux/amd64 node:22 as build
22

33
WORKDIR /app
44

@@ -7,7 +7,7 @@ COPY . .
77
RUN npm install && npm run build
88

99

10-
FROM --platform=linux/amd64 node:23
10+
FROM --platform=linux/amd64 node:22
1111

1212
WORKDIR /app
1313

fotobox/frontend-app/src/routes/+layout.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
9797
</script>
9898

99-
<Header persistentHamburgerMenu={true} company="IBM" platformName="Technology Sales Christmas Dinner" href="/" bind:isSideNavOpen>
99+
<Header persistentHamburgerMenu={true} company="IBM" platformName="Girls Day 2025" href="/" bind:isSideNavOpen>
100100
<svelte:fragment slot="skip-to-content">
101101
<SkipToContent />
102102
</svelte:fragment>

fotobox/frontend-app/src/routes/+page.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import { default as GridIcon } from "carbon-icons-svelte/lib/Grid.svelte";
1515
import {default as ParentChildIcon } from "carbon-icons-svelte/lib/ParentChild.svelte";
1616
17-
let url = "https://fotobox-frontend.1pbeufitp1uq.eu-de.codeengine.appdomain.cloud" // make dynamic
17+
let url = "https://gd-25-fotobox-frontend.8kyziehrspg.eu-de.codeengine.appdomain.cloud/" // make dynamic
1818
let qrCodeData = "";
1919
2020
const generateQRCode = async () => {
@@ -48,7 +48,7 @@
4848
<Grid>
4949
<Row>
5050
<Column>
51-
<h1>IBM Technology Sales Christmas Dinner</h1>
51+
<h1>IBM Girls Day 2025</h1>
5252
<h2>The easy way to save a snapshot of the Event</h2>
5353
</Column>
5454
</Row>

fotobox/frontend-app/src/stores.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import { writable } from 'svelte/store';
44
export const toggelGridTimer = writable(false);
55
export const toggleDownload = writable(false)
66

7-
export const uploadURL = "https://fotobox-cos-upload.1pbeufitp1uq.eu-de.codeengine.appdomain.cloud"
8-
export const downloadURL = "https://fotobox-get-pics.1pbeufitp1uq.eu-de.codeengine.appdomain.cloud"
7+
export let uploadURL = "https://gd-25-fotobox-cos-upload.8kyziehrspg.eu-de.codeengine.appdomain.cloud"
8+
export let downloadURL = "https://gd-25-fotobox-get-pics.8kyziehrspg.eu-de.codeengine.appdomain.cloud"

fotobox/setup.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
echo "create upload-function and download-application in code engine"
4+
5+
ibmcloud target -g Default
6+
7+
ibmcloud ce project select -n codeengine-fotobox-project # name of the project that was setup in terraform script
8+
9+
function_url=$(ibmcloud ce fn create --name fotobox-cos-upload --runtime python --build-source upload-function --env-from-configmap fotobox-config --env-from-secret fotobox-secret -o jsonpath={.endpoint})
10+
11+
app_url=$(ibmcloud ce app create --name fotobox-get-pics --build-dockerfile Dockerfile --build-source download-app --env-from-configmap fotobox-config --env-from-secret fotobox-secret -o jsonpath={.status.url})
12+
13+
echo "import { writable } from 'svelte/store';
14+
15+
// Create a writable store
16+
export const toggelGridTimer = writable(false);
17+
export const toggleDownload = writable(false)
18+
19+
export const uploadURL = \"$function_url\"
20+
export const downloadURL = \"$app_url\"
21+
" > ./frontend-app/src/stores.js
22+
23+
ibmcloud ce app create --name fotobox-frontend --build-dockerfile Dockerfile --build-source frontend-app
24+
25+
26+

fotobox/upload-function/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import random
88
from PIL import Image, ImageOps
99

10-
COS_ENDPOINT = "https://s3.eu-de.cloud-object-storage.appdomain.cloud"
10+
COS_ENDPOINT = os.environ.get('endpointURL', "https://s3.us-south.cloud-object-storage.appdomain.cloud")
1111
COS_API_KEY = os.environ.get('apikey', "apikey")
1212
COS_INSTANCE_CRN =os.environ.get('resource_instance_id', "resource_instance_id")
1313
COS_BUCKET_NAME = os.environ.get('bucket', "fotobox")

0 commit comments

Comments
 (0)