Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Langkah 2: Buat contoh revisi aplikasi
Pada langkah ini, Anda membuat contoh revisi aplikasi untuk diterapkan ke instans lokal Anda.
Karena sulit untuk mengetahui perangkat lunak dan fitur mana yang sudah terinstal—atau diizinkan untuk diinstal oleh kebijakan organisasi Anda—pada instans lokal Anda, contoh revisi aplikasi yang kami tawarkan di sini hanya menggunakan skrip batch (untuk Windows Server) atau skrip shell (untuk Server Ubuntu dan RHEL) untuk menulis file teks ke lokasi di instans lokal Anda. Satu file ditulis untuk masing-masing dari beberapa peristiwa siklus hidup CodeDeploy penerapan, termasuk Instal,, AfterInstall, ApplicationStartdan. ValidateService Selama peristiwa siklus hidup BeforeInstallpenerapan, skrip akan berjalan untuk menghapus file lama yang ditulis selama penerapan sampel ini sebelumnya dan membuat lokasi pada instance lokal untuk menulis file baru.
catatan
Contoh revisi aplikasi ini mungkin gagal diterapkan jika salah satu dari berikut ini benar:
- 
                    Pengguna yang memulai CodeDeploy agen pada instans lokal tidak memiliki izin untuk mengeksekusi skrip. 
- 
                    Pengguna tidak memiliki izin untuk membuat atau menghapus folder di lokasi yang tercantum dalam skrip. 
- 
                    Pengguna tidak memiliki izin untuk membuat file teks di lokasi yang tercantum dalam skrip. 
catatan
Jika Anda mengonfigurasi instance Windows Server dan ingin menyebarkan sampel yang berbeda, Anda mungkin ingin menggunakannya Langkah 2: Konfigurasikan konten sumber Anda untuk menyebarkan ke instans Amazon EC2 Windows Server di Tutorial: Menyebarkan “halo, dunia!” aplikasi dengan CodeDeploy (Windows Server) tutorial.
Jika Anda mengonfigurasi instance RHEL dan ingin menerapkan sampel yang berbeda, Anda mungkin ingin menggunakan contoh yang ada Langkah 2: Konfigurasikan konten sumber Anda untuk disebarkan ke instans Amazon Linux atau Red Hat Enterprise Linux Amazon EC2 di Tutorial: Terapkan WordPress ke EC2 instans Amazon (Amazon Linux atau Red Hat Enterprise Linux dan Linux, macOS, atau Unix) tutorial.
Saat ini, tidak ada contoh alternatif untuk Ubuntu Server.
- 
                Pada mesin pengembangan Anda, buat subdirektori (subfolder) bernama CodeDeployDemo-OnPremyang akan menyimpan file revisi aplikasi sampel, dan kemudian beralih ke subfolder. Untuk contoh ini, kami berasumsi Anda akan menggunakanc:\tempfolder sebagai folder root untuk Windows Server atau/tmpfolder sebagai folder root untuk Ubuntu Server dan RHEL. Jika Anda menggunakan folder yang berbeda, pastikan untuk menggantinya dengan folder kami di seluruh tutorial ini:Untuk Windows: mkdir c:\temp\CodeDeployDemo-OnPrem cd c:\temp\CodeDeployDemo-OnPremUntuk Linux, macOS, atau Unix: mkdir /tmp/CodeDeployDemo-OnPrem cd /tmp/CodeDeployDemo-OnPrem
- 
                Di root CodeDeployDemo-OnPremsubfolder, gunakan editor teks untuk membuat dua file bernamaappspec.ymldaninstall.txt:appspec.ymluntuk Windows Server:version: 0.0 os: windows files: - source: .\install.txt destination: c:\temp\CodeDeployExample hooks: BeforeInstall: - location: .\scripts\before-install.bat timeout: 900 AfterInstall: - location: .\scripts\after-install.bat timeout: 900 ApplicationStart: - location: .\scripts\application-start.bat timeout: 900 ValidateService: - location: .\scripts\validate-service.bat timeout: 900appspec.ymluntuk Server Ubuntu dan RHEL:version: 0.0 os: linux files: - source: ./install.txt destination: /tmp/CodeDeployExample hooks: BeforeInstall: - location: ./scripts/before-install.sh timeout: 900 AfterInstall: - location: ./scripts/after-install.sh timeout: 900 ApplicationStart: - location: ./scripts/application-start.sh timeout: 900 ValidateService: - location: ./scripts/validate-service.sh timeout: 900Untuk informasi selengkapnya tentang AppSpec file, lihat Tambahkan file spesifikasi aplikasi ke revisi untuk CodeDeploy danCodeDeploy AppSpec referensi file. install.txt:The Install deployment lifecycle event successfully completed.
- 
                Di bawah root CodeDeployDemo-OnPremsubfolder, buatscriptssubfolder, lalu beralih ke sana:Untuk Windows: mkdir c:\temp\CodeDeployDemo-OnPrem\scripts cd c:\temp\CodeDeployDemo-OnPrem\scriptsUntuk Linux, macOS, atau Unix: mkdir -p /tmp/CodeDeployDemo-OnPrem/scripts cd /tmp/CodeDeployDemo-OnPrem/scripts
- 
                Di root scriptssubfolder, gunakan editor teks untuk membuat empat file bernamabefore-install.bat,,, danvalidate-service.batuntuk Windows Serverafter-install.batapplication-start.bat, atau,,before-install.shafter-install.shapplication-start.sh, danvalidate-service.shuntuk Ubuntu Server dan RHEL:Untuk Windows Server: before-install.bat:set FOLDER=%HOMEDRIVE%\temp\CodeDeployExample if exist %FOLDER% ( rd /s /q "%FOLDER%" ) mkdir %FOLDER%after-install.bat:cd %HOMEDRIVE%\temp\CodeDeployExample echo The AfterInstall deployment lifecycle event successfully completed. > after-install.txtapplication-start.bat:cd %HOMEDRIVE%\temp\CodeDeployExample echo The ApplicationStart deployment lifecycle event successfully completed. > application-start.txtvalidate-service.bat:cd %HOMEDRIVE%\temp\CodeDeployExample echo The ValidateService deployment lifecycle event successfully completed. > validate-service.txtUntuk Server Ubuntu dan RHEL: before-install.sh:#!/bin/bash export FOLDER=/tmp/CodeDeployExample if [ -d $FOLDER ] then rm -rf $FOLDER fi mkdir -p $FOLDERafter-install.sh:#!/bin/bash cd /tmp/CodeDeployExample echo "The AfterInstall deployment lifecycle event successfully completed." > after-install.txtapplication-start.sh:#!/bin/bash cd /tmp/CodeDeployExample echo "The ApplicationStart deployment lifecycle event successfully completed." > application-start.txtvalidate-service.sh:#!/bin/bash cd /tmp/CodeDeployExample echo "The ValidateService deployment lifecycle event successfully completed." > validate-service.txt unset FOLDER
- 
                Untuk Ubuntu Server dan RHEL saja, pastikan keempat skrip shell memiliki izin eksekusi: chmod +x ./scripts/*