Last active
May 24, 2022 03:28
-
-
Save aryadiahmad4689/b77b122df9463a190e5011ba4eae42bb to your computer and use it in GitHub Desktop.
laravel-github-actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Laravel-github-action #nama pipeline bisa sesuai keinginan | |
on: | |
push: | |
branches: [ master ] # maksud dari ketiga kode diatas adalah dijalankan ketika ada push ke branch master | |
jobs: # pekerjaan yang akan dijalankan | |
laravel-tests: # nama pekerjaan | |
runs-on: ubuntu-latest # berjalan di os ubuntu | |
steps: # langkah-langkah yg dijalankan | |
- uses: actions/checkout@v3 # mengecekout dari github actions | |
- name: Copy .env | |
run: php -r "file_exists('.env') || copy('.env.example', '.env');" # mengecek apakah file .env sudah ada atau belum, jika belum maka akan menyalin file .env.example ke .env | |
- name: Install Dependencies | |
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist # install dependensi di laravel yg diperlukan | |
- name: Generate key | |
run: php artisan key:generate # generate key laravel | |
- name: Directory Permissions | |
run: chmod -R 777 storage bootstrap/cache # mengubah permission untuk storage, bootstrap/cache | |
- name: Create Database # membuat database untuk keperluan testing | |
run: | | |
mkdir -p database | |
touch database/database.sqlite | |
- name: Execute tests (Unit and Feature tests) via PHPUnit | |
env: | |
DB_CONNECTION: sqlite | |
DB_DATABASE: database/database.sqlite | |
run: vendor/bin/phpunit --testdox # menjalankan phpunit dengan testdox | |
# materi ci sampai disini | |
# materi cd dibawah | |
deploy: # nama pekerjaan | |
name: Setup Gcloud Account | |
runs-on: ubuntu-latest # berjalan di os ubuntu | |
env: | |
IMAGE_NAME: gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_APP_NAME }} # nama image yg akan di deploy | |
steps: | |
- name: Login | |
uses: google-github-actions/setup-gcloud@v0 # login ke gcloud | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} # project id | |
service_account_email: ${{ secrets.GCP_EMAIL }} # email service account | |
service_account_key: ${{ secrets.GCP_CREDENTIALS }} # key service account | |
- name: Configure Docker | |
run: gcloud auth configure-docker --quiet # mengkonfigurasi docker | |
- name: Checkout repository | |
uses: actions/checkout@v2 # mengecekout dari github actions | |
- name: Build Docker image | |
run: docker build . -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_APP_NAME }} # membuat image dari laravel yg di deploy | |
- name: Push Docker image | |
run: docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_APP_NAME }} # mengirim image ke gcloud | |
- name: Deploy Docker image | |
run: gcloud run deploy ${{ secrets.GCP_PROJECT_ID }} --image gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_APP_NAME }} --region us-central1 --platform managed --allow-unauthenticated --port 8001 # deploy image ke gcloud |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment