接下來,建立 Web 應用程式。 dev 空間是您組織的預設選項,但您可能偏好建立其他空間來隔離不同的工作。 例如,將 'finance' 與 '開發' 分開。
ibmcloud dev create
有了這個命令你就會被問一系列問題 您可以在處理程序中的許多點回復,因此如果您覺得遺失,可以從刪除現有目錄並建立新目錄重新開始。 即使在指令行上建立應用程式,您仍會在 IBM Cloud 主控台中看到結果。
請注意用於建立「Web 應用程式」的選項。 那是你想要的
===============================================================================
Select an application type:
1. Backend Service / Web App
2. Mobile App
-------------------------
0. Exit
===============================================================================
? Enter selection number:> 1
提供了許多選項,但您想要 'Node'。 鍵入 '4',然後按 Enter 鍵。
===============================================================================
Select a language:
1. Go
2. Java - MicroProfile / Java EE
3. Java - Spring
4. Node
5. Python - Django
6. Python - Flask
7. Swift
-------------------------
0. Return to the previous selection
===============================================================================
? Enter selection number:> 4
在您選擇程式設計語言和架構之後,下一個選擇將會有許多選項,它可能會捲動瀏覽您想要的服務。 如您在範例中所見,您想要搭配使用簡式 Node.js Web 應用程式與 Express.js。鍵入 '3' 並按 Enter 鍵。
===============================================================================
Select a Starter Kit:
APPSERVICE
-------------------------------------------------------------------------------
1. Node-RED - A starter to run the Node-RED open-source project on
IBM Cloud.
2. Node.js + Cloudant - A web application with Node.js and Cloudant
3. Node.js Express App - Start building your next Node.js Express
app on IBM Cloud.
WATSON
-------------------------------------------------------------------------------
4. Natural Language Understanding Node.js App - Use Watson Natural
Language Understanding to analyze text to help you understand its
concepts, entities, keywords, sentiment, and more.
5. Speech to Text Node.js App - React app using the Watson Speech to
Text service to transform voice audio into written text.
6. Text to Speech Node.js App - React app using the Watson Text to
Speech service to transform text into audio.
7. Visual Recognition Node.js App - React app using the Watson
Visual Recognition service to analyze images for scenes, objects, text,
and other subjects.
-------------------------
0. Return to the previous selection
===============================================================================
? Enter selection number:> 3
各地開發人員仍需要最難的選項: 命名您的應用程式。 遵循範例並鍵入 webapplication,然後按 Enter 鍵。
? Enter a name for your application> webapplication
稍後,您可以根據需要透過 Web 控制台新增任意數量的服務,例如資料儲存或運算功能。 不過,當詢問您是否要立即新增服務時,鍵入 ' n' 表示 no。 此外,如果您尚未設定資源群組,此時可能會提示您。 您可以在此提示中鍵入 ' n' 來跳過此動作。
Using the resource group Default (default) of your account
? Do you want to select a service to add to this application? [Y/n]> n
===============================================================================
Select from the following DevOps toolchain and target runtime environment
options:
1. IBM DevOps, deploy to Knative-based Kubernetes containers
2. IBM DevOps, deploy to Helm-based Kubernetes containers
3. IBM DevOps, deploy to Helm-based Red Hat OpenShift containers
4. No DevOps, with manual deployment
===============================================================================
? Enter selection number:> 4
您必須選擇自動化部署 CD 工具鏈的地區。 請選取參照先前所選的相同區域 '5' 的選項。
--------------------------------------------------------------------------------
Select a region for your toolchain from the following options:
--------------------------------------------------------------------------------
1. eu-de (Frankfurt)
2. eu-gb (London)
3. jp-tok
4. us-east (Washington DC)
5. us-south (Dallas)
--------------------------------------------------------------------------------
0. Return to the previous selection
--------------------------------------------------------------------------------
? Enter selection number:> 5
產生新的應用程式會提醒我們用來部署應用程式的工具鏈需要一些其他配置。 如前所述,需要將公鑰上傳到GitHub (在IBM Cloud平台上的 CD 工具鏈實例中)才能使用GitHub交付已部署的應用程式。
Note: For successful connection to the DevOps toolchain, this machine
must be configured for SSH access to your IBM Cloud GitLab account at
https://git.cloud.ibm.com/profile/keys in order to download the
application code.
The DevOps toolchain for this app will be: webapplication
? Press [Enter] to accept this, or enter a new value now>
The hostname for this app will be: webapplication
? Press [Enter] to accept this, or enter a new value now>
The app webapplication has been created in IBM Cloud.
DevOps toolchain created at
https://cloud.ibm.com/devops/toolchains/6ffb568a-e48f-4e27-aed0-00ca931dde66?env_id=ibm:yp:us-south
如果您複製並貼上 ibmcloud dev create 指令所傳回的鏈結,您也可以存取 CD Toolchain。 您可以稍後從控制台訪問該鏈接,以防您錯過捕獲鏈接。 以下是進一步資訊,因為處理程序會繼續在線上建立應用程式項目,以及具有範例程式碼的目錄。
Cloning repository
https://git.cloud.ibm.com/Organization.Name/webapplication...
Cloning into 'webapplication'...
remote: Counting objects: 60, done.
remote: Compressing objects: 100% (54/54), done.
remote: Total 60 (delta 4), reused 0 (delta 0)
Receiving objects: 100% (60/60), 50.04 KiB | 1.52 MiB/s, done.
Resolving deltas: 100% (4/4), done.
OK
The app, webapplication, has been successfully saved into the
current directory.
若要使用您對 IBM Cloud Platform 的變更來取得入門範本應用程式,請重複您先前執行的相同步驟,以使用 Developer Tools 來部署它。
如果您尚未登錄,或已重新啟動或登出,請使用 login 指令登入IBM Cloud平台。
ibmcloud login
使用 api 指令來設定地區的 API 端點。
ibmcloud api cloud.ibm.com
使用建置命令建置應用程式以交付該應用程式(如範例所示)。
ibmcloud dev build
繼續並在本端測試應用程式。 這可讓您使用 run 指令在本端執行相同的程式碼。
ibmcloud dev run
使用 deploy 指令將應用程式部署至 IBM Cloud Platform。
ibmcloud dev deploy
該程式碼顯示了本範例中用於建置、測試和部署初始 Web 應用程式的命令序列。
ibmcloud login --sso
ibmcloud api cloud.ibm.com
ibmcloud target --cf
ibmcloud dev enable
ibmcloud dev build
ibmcloud dev run
ibmcloud dev deploy
當程序完成時,IBM Cloud 平台會報告已上傳、順利部署並啟動應用程式。 如果您也登入了IBM Cloud平台 Web 控制台,您也會收到應用程式狀態的通知。 但是,最重要的是,您可以使用瀏覽器來造訪 IBM Cloud Platform 所報告的應用程式 URL,或從 Web 主控台按一下「檢視應用程式」按鈕,來驗證已部署該應用程式。
測試應用程式。 建立時部署至下面所示的入門範本應用程式的預設應用程式範本的可見變更,證明已成功將應用程式部署至 IBM Cloud Platform。
var express = require('express');
var cfenv = require('cfenv');
var bodyParser = require('body-parser');
var app = express();
//...// start server on the specified port and binding hostvar port = process.env.PORT || 3000;
app.listen(port, function() {
console.log("To view your app, open this link in your browser: http://localhost:" + port);
});
//...
//...// serve the files out of ./public as your main files
app.use(express.static('public'));
app.set('views', './src/views');
app.set('view engine', 'ejs');
app.use(bodyParser.json());
var title = 'COS Image Gallery Web Application';
// Serve index.ejs
app.get('/', function (req, res) {
res.render('index', {status: '', title: title});
});
//...