-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jason Peterson <[email protected]> Co-authored-by: whitesource-ets[bot] <328400+whitesource-ets[bot]@users.noreply.github.ibm.com> Co-authored-by: Michael Magrian <[email protected]> Co-authored-by: Enrico Regge <[email protected]> Co-authored-by: John Sartore <[email protected]> Co-authored-by: semantic-release-bot <[email protected]> Co-authored-by: whitesource-ets[bot] <409986+whitesource-ets[bot]@users.noreply.github.ibm.com> Co-authored-by: whitesource-ets[bot] <whitesource-ets[bot]@users.noreply.github.ibm.com>
- Loading branch information
1 parent
99e81b3
commit 44442df
Showing
8 changed files
with
925 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Code Engine Go SDK Example | ||
|
||
## Running example_v2.go | ||
|
||
To run the example, create a Code Engine project from the Console or Code Engine CLI, and run the following commands from this directory: | ||
1. `export CE_API_KEY=<Your IBM Cloud API key>` | ||
2. `export CE_PROJECT_REGION=<The region (e.g. 'us-south') of your Code Engine project>` | ||
3. `export CE_DOMAIN_MAPPING_NAME=<The name of your domain>` | ||
4. `export CE_TLS_CERT_FILE_PATH=<The path to your TLS certificate file>` | ||
5. `export CE_TLS_KEY_FILE_PATH=<The path to your TLS key file>` | ||
6. `go run example_v2.go` | ||
|
||
## How-to | ||
|
||
### Set up an authenticator | ||
```go | ||
authenticator := &core.IamAuthenticator{ | ||
ApiKey: os.Getenv("CE_API_KEY"), | ||
ClientId: "bx", | ||
ClientSecret: "bx", | ||
URL: "https://iam.cloud.ibm.com", | ||
} | ||
``` | ||
|
||
### Set up a Code Engine client | ||
```go | ||
codeEngineServiceOptions := &codeenginev2.CodeEngineV2Options{ | ||
Authenticator: authenticator, | ||
URL: "https://api." + os.Getenv("CE_PROJECT_REGION") + ".codeengine.cloud.ibm.com/v2", | ||
} | ||
codeEngineService, err := codeenginev2.NewCodeEngineV2UsingExternalConfig(codeEngineServiceOptions) | ||
``` | ||
|
||
### Create a Code Engine project | ||
```go | ||
projectName := "my-project" | ||
createdProject, _, err := codeEngineService.CreateProject(&codeenginev2.CreateProjectOptions{ | ||
Name: &projectName, | ||
}) | ||
``` | ||
|
||
### Create a Code Engine application | ||
```go | ||
createAppOpts := codeEngineService.NewCreateAppOptions( | ||
*createdProject.ID, | ||
"icr.io/codeengine/helloworld", | ||
"my-app", | ||
) | ||
createdApp, _, err := codeEngineService.CreateApp(createAppOpts) | ||
``` | ||
|
||
### Create a Code Engine TLS secret | ||
```go | ||
createTLSSecretOpts := codeEngineService.NewCreateSecretOptions( | ||
*createdProject.ID, | ||
"tls", | ||
"my-tls-secret", | ||
) | ||
|
||
tlsCert, _ := os.ReadFile(os.Getenv("CE_TLS_CERT_FILE_PATH")) | ||
tlsKey, _ := os.ReadFile(os.Getenv("CE_TLS_KEY_FILE_PATH")) | ||
|
||
createTLSSecretOpts.Data = &codeenginev2.SecretDataTLSSecretData{ | ||
TlsCert: core.StringPtr(string(tlsCert)), | ||
TlsKey: core.StringPtr(string(tlsKey)), | ||
} | ||
createdTLSSecret, _, err := codeEngineService.CreateSecret(createTLSSecretOpts) | ||
``` | ||
|
||
### Create a Code Engine domain mapping | ||
```go | ||
domainMappingName := os.Getenv("CE_DOMAIN_MAPPING_NAME") | ||
appComponentRef := &codeenginev2.ComponentRef{ | ||
Name: createdApp.Name, | ||
ResourceType: core.StringPtr("app_v2"), | ||
} | ||
|
||
createDomainMappingOpts := codeEngineService.NewCreateDomainMappingOptions( | ||
*createdProject.ID, | ||
appComponentRef, | ||
domainMappingName, | ||
*createdTLSSecret.Name, | ||
) | ||
createdDomainMapping, _, err := codeEngineService.CreateDomainMapping(createDomainMappingOpts) | ||
``` |
Oops, something went wrong.