Image Builder bileşenleri ve şablonları için YAML ve Dockerfile komutlarının sözdizimini ve kullanımını öğrenin.
Komut sözdizimi
Image Builder iki komut biçimini destekler: YAML (Linux ve Windows) ve Dockerfile (yalnızca Linux).
Dockerfile komutları daha az esnektir ve yalnızca Linux ile sınırlıdır. Mümkün olduğunda YAML biçimini kullanın.
YAML ve Dockerfile biçimleri aşağıdaki sözdizimini kullanır:
-
YAML:
ParametersveTasksbölümlerini tanımlayın:Parameters: # Optional. Defines custom parameters. param1: # Required. The name of the parameter. Type: String # Required. The type of the parameter. Valid values: String, Number, and Boolean. DefaultValue: defaultValue # Optional. The default value of the parameter. If no default value is specified, you must explicitly pass a value when you use the image component in an image template. Tasks: # Required. Defines a list of tasks for the image component. The tasks are run in sequence. At least one task must be included. - Name: taskName1 # Required. The name of the task. Action: RunShellCommand # Required. The action for the task. For more information, see the YAML-format component commands. Properties: # The properties of the action. The available properties depend on the specified action. commandContent: echo {{ param1 }} # References a custom parameter. - Name: taskName2 Action: action2 Properties: action2Property1: {{ taskName1.stdout }} # References the output of taskName1.NotTanımlanan parametrelere görev özelliklerinden şu şekilde başvurun:
{{taskName1.stdout}} -
Dockerfile
Her satır tek bir komut içerir.
Bir komut birden fazla satıra yayılabilir. Sonraki satıra devam etmek için her satırın sonuna ters eğik çizgi (\) ekleyin.
Desteklenen komutlar
Image Builder, bileşenler ve şablonlar için aşağıdaki komutları destekler.
Bileşen komutları
YAML biçimi
|
Komut |
Sözdizimi |
Açıklama |
Çıktı |
|
RunShellCommand |
|
|
|
|
RunPowerShellCommand |
|
|
|
|
InvokeCommand |
|
Ortak bir komutu çalıştırır. |
|
|
OSSDownload |
|
|
Yok |
|
OSSUpload |
|
|
|
|
WebDownload |
|
Bir dosyayı bir web URL'sinden indirir. |
|
|
Reboot |
|
Örneği yeniden başlatır. |
Dockerfile biçimi
|
Komut |
Sözdizimi |
Açıklama |
|
RESTART |
|
|
|
RUN |
|
|
|
ENV |
|
Not
|
|
WORKDIR |
|
Çalışma dizinini ayarlar. |
|
COPY |
|
Dosyaları kopyalar. Not
Ağ dosyaları |
|
USER |
|
Sonraki Not
|
|
LABEL |
|
|
|
CMD |
|
Başlangıçta çalıştırılacak komutu belirtir. |
|
ENTRYPOINT |
|
Başlangıçta çalıştırılacak komutu belirtir. Not
|
Şablon komutları
|
Komut |
Sözdizimi |
Açıklama |
|
COMPONENT |
|
Bir sistem veya özel görüntü bileşeni belirtir.
|
|
RESTART |
|
|
|
RUN |
|
|
|
ENV |
|
Not
|
|
WORKDIR |
|
|
|
COPY |
|
Not
Ağ dosyaları |
|
USER |
|
Not
|
|
LABEL |
|
|
|
CMD |
|
|
|
ENTRYPOINT |
|
Not
|
Komut örnekleri
Aşağıdaki örneklerde, yaygın kullanım durumları için bileşen ve şablon komutları gösterilmektedir.
Bileşen komutları
Örnek 1: Özel parametreleri kullanma
Bu bileşen, x, y ve z özel parametreleriyle (3x+2y+z)+(3x+2y+z) hesaplamasını yapar. İlgili şablon komutu için bkz. Örnek 1: Bir şablonu bir bileşenle ilişkilendirme ve özel parametrelerine değer atama.
Parameters:
x:
Type: String
y:
Type: String
z:
Type: String
Tasks:
- Name: count
Action: RunShellCommand
Properties:
commandContent: echo $((3 * {{x}} + 2 * {{y}} + {{z}}))
- Name: result
Action: RunShellCommand
Properties:
commandContent: echo $(({{count.stdout}}+{{count.stdout}}))
Örnek 2: OSS'ten bir betiği yapılandırma
Benzer şekilde yapılandırılmış ECS örnekleri oluşturmak için OSS'teki bir Linux betiğinden bir görüntü oluşturun. OSSDownload ve OSSUpload eylemleri, AccessKey çiftlerinin sabit kodlanmasını gerektirmez.
Tasks:
- Name: ossdownload
Action: OSSDownload
Properties:
bucketName: <your_oss_bucket_name>
destinationDir: /home
objectName: <your_script_object_name>
- Name: setpermissions
Action: RunShellCommand
Properties:
commandContent: sudo chmod +x /home/<your_script_object_name>
- Name: createfile
Action: RunShellCommand
Properties:
commandContent: sudo touch /home/output.txt
- Name: setfilepermissions
Action: RunShellCommand
Properties:
commandContent: sudo chmod 666 /home/output.txt
- Name: result
Action: RunShellCommand
Properties:
commandContent: sudo bash /home/<your_script_object_name> &> /home/output.txt
- Name: ossupload
Action: OSSUpload
Properties:
bucketName: <your_oss_bucket_name>
fileToUpload: /home/output.txt
objectName: output.txt
Şablon komutları
Örnek 1: Bir bileşeni ilişkilendirme ve parametre atama
Örnek 1: Bir bileşende özel parametreleri kullanma konusundaki x, y ve z parametrelerine değer atayın.
COMPONENT i-xxxxxxxxx --x 1 --y 2 --z 3
Örnek 2: En son bileşen sürümünü kullanma
1.0.1, 1.0.2 ve 1.0.3 sürümlerine sahip bir bileşen için en son eşleşen sürümü (1.0.3) kullanmak üzere 1.0.* belirtin.
COMPONENT acs:ecs:cn-hangzhou:<alibaba_cloud_account_id>:imagecomponent/<your_component_name>/1.0.*