-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.justfile
122 lines (99 loc) · 4.34 KB
/
.justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
set dotenv-load
# Build
build-image:
@podman build -t cloud-native-store .
# Generate an encryption key.
genkey:
@go run cmd/genkey/main.go
# Run the service.
run:
@go run cmd/service/main.go
# Run the service in a container.
run-container:
@podman run -p 8080:8080 \
-e ENCRYPTION_KEY=$ENCRYPTION_KEY \
-e PORT=8080 \
cloud-native-store
# Test the Go sources (Units).
test:
@go test -v -coverprofile=.coverprofile.out ./internal/app/core/services/...
# Set up "Cloud Build" according to https://cloud.google.com/build/docs/build-push-docker-image.
# Check if billing is enabled at: https://cloud.google.com/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project
cloud-build-setup:
# Enable the Artifact Registry, Cloud Build and Compute Engine APIs.
@gcloud services enable \
artifactregistry.googleapis.com \
cloudbuild.googleapis.com \
compute.googleapis.com
# Add the artifactregistry.writer role.
@gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
--member=serviceAccount:$(gcloud projects describe $GCP_PROJECT_ID \
--format="value(projectNumber)")-compute@developer.gserviceaccount.com \
--role="roles/artifactregistry.writer"
# Add the storage.admin role.
@gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
--member=serviceAccount:$(gcloud projects describe $GCP_PROJECT_ID \
--format="value(projectNumber)")-compute@developer.gserviceaccount.com \
--role="roles/storage.admin"
# Add the iam.serviceAccountUser role, which includes the actAspermission to deploy to the runtime.
@gcloud iam service-accounts add-iam-policy-binding $(gcloud projects describe $GCP_PROJECT_ID \
--format="value(projectNumber)")-compute@developer.gserviceaccount.com \
--member=serviceAccount:$(gcloud projects describe $GCP_PROJECT_ID \
--format="value(projectNumber)")-compute@developer.gserviceaccount.com \
--role="roles/iam.serviceAccountUser" \
--project=$GCP_PROJECT_ID
# Create a new Docker repository.
@gcloud artifacts repositories create $GCP_DOCKER_REPOSITORY --repository-format=docker \
--location=$GCP_REGION --description="Docker repository"
@gcloud artifacts repositories list
# Build a docker image using Google Cloud Build.
cloud-build:
@gcloud builds submit --region=$GCP_REGION \
--tag $GCP_REGION-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_DOCKER_REPOSITORY/$GCP_DOCKER_IMAGE
# Set up Google Cloud SDK.
cloud-cli-setup:
# Login and set up the project.
@gcloud auth application-default login
# Set the project and region.
@gcloud config set project $GCP_PROJECT_ID
@gcloud config set functions/region $GCP_REGION
@gcloud config set run/region $GCP_REGION
# Disable usage reporting.
@gcloud config set disable_usage_reporting false
# Update the components.
@gcloud components update
# Set up Google Cloud Run.
cloud-run-setup:
# Enable the Cloud Run APIs.
@gcloud services enable \
run.googleapis.com
# Run a docker container based on a Google Cloud Build.
cloud-run:
# Deploy the service.
@gcloud run deploy $GCP_SERVICE \
--image $GCP_REGION-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_DOCKER_REPOSITORY/$GCP_DOCKER_IMAGE \
--allow-unauthenticated
# Make service public accessible.
@gcloud run services add-iam-policy-binding $GCP_SERVICE \
--member="allUsers" \
--role="roles/run.invoker"
# Set up Google Cloud Spanner.
cloud-spanner-setup:
# Enable the Cloud Storage API.
@gcloud services enable \
spanner.googleapis.com
# Create a new instance.
@gcloud spanner instances create $GCP_SPANNER_INSTANCE_ID \
--config="regional-$GCP_REGION" \
--description="Regional Cloud Spanner" \
--nodes=2
# Create a new database.
@gcloud spanner databases create $GCP_SPANNER_DATABASE_ID \
--instance=$GCP_SPANNER_INSTANCE_ID
# Create a new table.
@gcloud spanner databases ddl update $GCP_SPANNER_DATABASE_ID \
--instance=$GCP_SPANNER_INSTANCE_ID \
--ddl="CREATE TABLE KeyValueStore (Key STRING(MAX) NOT NULL, Value STRING(MAX)) PRIMARY KEY (Key)"
# Verify the instance.
@gcloud spanner instances list
@gcloud spanner databases list --instance=$GCP_SPANNER_INSTANCE_ID