Skip to content

Commit e9fdb7b

Browse files
chore(build): validate Code Engine registry secret and clarify env loading
Signed-off-by: prakhar-singh1928 <prakhar.singh1928@ibm.com>
1 parent b13ebe4 commit e9fdb7b

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6255,6 +6255,26 @@ ibmcloud-push:
62556255
ibmcloud-deploy:
62566256
@test -f .env || { echo "❌ Missing .env — run: cp .env.example .env"; exit 1; }
62576257
@echo "🚀 Deploying image to Code Engine as '$(IBMCLOUD_CODE_ENGINE_APP)' using registry secret $(IBMCLOUD_REGISTRY_SECRET)..."
6258+
@# Verify the registry pull secret exists before attempting deploy.
6259+
@# Capture stderr so we can distinguish "secret not found" from auth/plugin/network failures.
6260+
@_secret_err=$$(ibmcloud ce secret get --name $(IBMCLOUD_REGISTRY_SECRET) 2>&1 >/dev/null); \
6261+
_secret_rc=$$?; \
6262+
if [ $$_secret_rc -ne 0 ]; then \
6263+
if echo "$$_secret_err" | grep -qi "not found"; then \
6264+
echo "❌ Registry pull secret '$(IBMCLOUD_REGISTRY_SECRET)' does not exist."; \
6265+
echo " Create it first (first-time setup only):"; \
6266+
echo " ibmcloud ce secret create --name $(IBMCLOUD_REGISTRY_SECRET) \\"; \
6267+
echo " --format registry \\"; \
6268+
echo " --server $$(echo $(IBMCLOUD_IMAGE_NAME) | cut -d/ -f1) \\"; \
6269+
echo " --username iamapikey --password \$$IBMCLOUD_API_KEY"; \
6270+
echo " See the docs for alternative credential types (service ID keys, etc.)."; \
6271+
else \
6272+
echo "❌ Could not verify registry pull secret '$(IBMCLOUD_REGISTRY_SECRET)'."; \
6273+
echo " Diagnostic: $$_secret_err"; \
6274+
echo " Check your IBM Cloud login, region, CE project selection, and plugin installation."; \
6275+
fi; \
6276+
exit 1; \
6277+
fi
62586278
@# Create the runtime env secret from .env if it does not exist yet
62596279
@if ! ibmcloud ce secret get --name $(IBMCLOUD_CODE_ENGINE_APP)-env > /dev/null 2>&1; then \
62606280
echo "🔐 Creating runtime env secret from .env..."; \

docs/docs/howto/ibm-cloud-code-engine.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,22 @@ make ibmcloud-ce-login
166166
make podman # or: make docker
167167
make ibmcloud-tag
168168
make ibmcloud-push
169+
# First time only: create the registry pull secret (see note below)
170+
ibmcloud ce secret create --name "$IBMCLOUD_REGISTRY_SECRET" \
171+
--format registry \
172+
--server "$(echo "$IBMCLOUD_IMAGE_NAME" | cut -d/ -f1)" \
173+
--username iamapikey --password "$IBMCLOUD_API_KEY"
169174
make ibmcloud-deploy
170175
```
171176

172-
!!! info "`make ibmcloud-deploy` handles env injection automatically"
177+
!!! info "Registry pull secret — first-time setup"
178+
`make ibmcloud-deploy` **requires** a registry pull secret named `$IBMCLOUD_REGISTRY_SECRET`
179+
to exist before it runs. It validates this and exits with a helpful error if the secret is
180+
missing. The example above uses an IAM API key (`iamapikey`), but you can use any credential
181+
type accepted by `ibmcloud ce secret create --format registry` — for example a service ID key.
182+
Create the secret once; subsequent deploys reuse it.
183+
184+
!!! info "`make ibmcloud-deploy` manages the runtime env secret automatically"
173185
The target creates or updates a Code Engine secret named `<app>-env` (where `<app>` is
174186
`$IBMCLOUD_CODE_ENGINE_APP`) from your local `.env` on every run, then passes
175187
`--env-from-secret <app>-env` to the app. You do not need a
@@ -202,6 +214,17 @@ ibmcloud ce application update --name "$IBMCLOUD_CODE_ENGINE_APP"
202214

203215
## 4 - Workflow B - Manual IBM Cloud CLI
204216

217+
!!! tip "Load `.env.ce` into your shell first"
218+
The CLI commands below reference `$IBMCLOUD_*` variables defined in `.env.ce`.
219+
Export them once before running any step:
220+
221+
```bash
222+
export $(grep -v '^#' .env.ce | grep -v '^$' | xargs)
223+
```
224+
225+
Without this step every `$IBMCLOUD_*` reference expands to an empty string and
226+
commands fail with errors such as `Required flag "name" not set`.
227+
205228
```bash
206229
# 1 - Install the IBM Cloud CLI using the official instructions:
207230
# https://cloud.ibm.com/docs/cli?topic=cli-getting-started

0 commit comments

Comments
 (0)