次に、Web アプリケーションを作成します。 dev スペースは組織のデフォルト・オプションですが、さまざまな作業を分離するために他のスペースを作成することもできます。 例えば、「finance」を「development」とは別に保持します。
ibmcloud dev create
このコマンドを使用すると、一連の質問が表示されます。 プロセスの多くのポイントに戻ることができるため、失われたと感じる場合は、既存のディレクトリーを削除して新規ディレクトリーを作成することからやり直すことができます。 コマンド・ラインでアプリケーションを作成した場合でも、 IBM Cloud コンソールに結果が表示されます。
「Web アプリ」を作成するためのオプションに注意してください。 それが欲しいんだろ
===============================================================================
Select an application type:
1. Backend Service / Web App
2. Mobile App
-------------------------
0. Exit
===============================================================================
? Enter selection number:> 1
===============================================================================
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
プログラミング言語とフレームワークを選択すると、次の選択には非常に多くのオプションがあり、希望するサービスを超えてスクロールする可能性があります。 例に示されているように、 Express.jsで単純な Node.js Web アプリを使用したいと考えています。 「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
===============================================================================
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 Toolchainインスタンス)に公開鍵をアップロードする必要があります。Platform)に公開鍵をアップロードすることが、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 ツールチェーンにアクセスすることもできます。 リンクをキャプチャし損ねた場合は、後でコンソールからアクセスできる。 プロセスがアプリケーション・エントリーをオンラインで作成し続けるとともに、サンプル・コードを含むディレクトリーも作成し続けると、さらに詳しい情報が続きます。
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.
アプリがビルドされたので、 run コマンドを使用してコードをローカルで実行できます。 When finished, copy and paste the provided URL into your browser's address bar, typically, http://localhost:3000.
前に指定したリージョン・エンドポイントとホスト名に基づいて、 ibmcloud dev deploy によって URL が再度表示されます。 IBM Cloud Platform で、ポータルに保管されているログへのリンクを確認できます。 では、クラウド内の新しい Web アプリケーションにアクセスしてみましょう。
Web ギャラリー・アプリケーションの作成
IBM Cloud上でNode.jsアプリを開発するために必要な前提条件を思い出してみよう。プラットフォーム。 IBM Cloud プラットフォーム・アカウントを作成して、開発者ツールをインストールし、それにより Docker もインストールされました。 次に、 Node.jsをインストールします。 このチュートリアルの前提条件としてリストされている最後の項目は Gitです。これについては、ここで詳しく説明します。
Web アプリケーションの Object Storage 資格情報と、イメージの保管および取得を行う「バケット」を構成する必要があります。 The API key that you will create will need Object Storage HMAC credentials, as defined by your サービス資格.
access_key_id と'secret_access_key という用語は、あなたがAWSアカウントを持っていて、すでに'aws_access_key_id と'aws_secret_access_key エントリを持つ資格情報ファイルを使用しているかもしれないので、認識するかもしれない。
API キーの作成が完了し、ダウンロードし、HMAC 資格情報をコピーしたら、以下のステップを実行します。
ローカル開発環境で、資格情報を Windows パス %USERPROFILE%\\.aws\\credentials に配置します。 Mac/Linux ユーザーの場合、資格情報は ~/.aws/credentials) に移動する必要があります。 この例は典型的なクレデンシャル・ファイルの内容を示している。
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});
});
//...
var express = require('express');
var imageUploadRoutes = express.Router();
var status = '';
var router = function(title) {
var galleryController =
require('../controllers/galleryController')(title);
imageUploadRoutes.route('/')
.post(
galleryController.upload.array('img-file', 1), function (req, res, next) {
if (res.statusCode === 200 && req.files.length > 0) {
status = 'uploaded file successfully';
}
else {
status = 'upload failed';
}
res.render('index', {status: status, title: title});
});
return imageUploadRoutes;
};
module.exports = router;
それに比べ、「galleryRouter コードはシンプルさの見本だ。 imageUploadRouter で行ったのと同じパターンで、関数の最初の行で'galleryController 要求し、それからルートを設定する。 The main difference is that you are routing HTTP GET requests rather than
POST, and sending all the output in the response from getGalleryImages, which is exposed by the galleryController on the last line of the example.
var express = require('express');
var galleryRouter = express.Router();
var router = function(title) {
var galleryController =
require('../controllers/galleryController')(title);
galleryRouter.route('/')
.get(galleryController.getGalleryImages);
return galleryRouter;
};
module.exports = router;