＜手順整理＞Flyデプロイ

概要
-
【PHP/Laravel】プログラミング初学者によるアプリケーション開発
https://qiita.com/AlpacaFace/items/b8e05a3da599815d8e31

上記トークアプリ開発のデプロイを説明します。

前提条件
-
- GUI画面で以下を実施済みであること。
- Fly.ioへユーザ登録
- Fly.ioへログイン

手順整理　ターミナル操作
-


■対象ブランチの最新化
-
    $ pwd
    → ~（任意の場所）~/joint_develop_docker/src/laravelapp

    $ git branch
    → * （対象のブランチ名）

    $ git pull origin　（対象のブランチ名）

    $ docker exec -it laravel_app bash

    # ls
    → laravelapp

    # cd laravelapp ; pwd
    → /var/www/html/laravelapp

    # php artisan migrate:fresh --seed
    Dropped all tables successfully.
    Migration table created successfully.
    Migrating: 2014_10_12_000000_create_users_table
    Migrated:  2014_10_12_000000_create_users_table (0.18 seconds)
    Migrating: 2014_10_12_100000_create_password_resets_table
    Migrated:  2014_10_12_100000_create_password_resets_table (0.14 seconds)
    Migrating: 2019_08_19_000000_create_failed_jobs_table
    Migrated:  2019_08_19_000000_create_failed_jobs_table (0.08 seconds)
    Migrating: 2023_01_11_234631_create_posts_table
    Migrated:  2023_01_11_234631_create_posts_table (0.29 seconds)
    Migrating: 2023_02_11_152043_create_follow_users_table
    Migrated:  2023_02_11_152043_create_follow_users_table (0.55 seconds)
    Seeding: UsersTableSeeder
    Seeded:  UsersTableSeeder (0.96 seconds)
    Seeding: PostsTableSeeder
    Seeded:  PostsTableSeeder (0.04 seconds)
    Seeding: FollowsTableSeeder
    Seeded:  FollowsTableSeeder (0.18 seconds)
    Database seeding completed successfully.

    # exit

    $ date ; pwd

        yyyy年 mm月dd日 水曜日 21時19分05秒 JST
        /（任意の場所）/joint_develop_docker/src/laravelapp

    $ git branch
    → * （対象のブランチ名）



■Fly 操作
-
 
    $ curl -L https://fly.io/install.sh | sh

    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  1475    0  1475    0     0   2993      0 --:--:-- --:--:-- --:--:--  3028
    ######################################################################## 100.0%
    set channel to shell
    flyctl was installed successfully to /(任意の場所)/.fly/bin/flyctl
    Manually add the directory to your $HOME/.zshrc (or similar)
      export FLYCTL_INSTALL="/(任意の場所)/.fly"
      export PATH="$FLYCTL_INSTALL/bin:$PATH"
    Run '/(任意の場所)/.fly/bin/flyctl --help' to get started


    $ flyctl auth login

    Opening https://fly.io/app/auth/cli/3ab10410dc5e4b5c99f214003fd3d711 ...
    
    Waiting for session... Done
    successfully logged in as （Flyに登録したメールアドレス）



    $ flyctl launch
    → Creating app in （任意の場所）/joint_develop_docker/src/laravelapp
    → Scanning source code
    → Detected a Laravel app
    ? Choose an app name (leave blank to generate one): （任意）
    automatically selected personal organization:（任意）
    Some regions require a paid plan (fra, maa).
    See https://fly.io/plans to set up a plan.

    ? Choose a region for deployment: Tokyo, Japan (nrt)
    Created app 'geanimusicboard' in organization 'personal'
    Admin URL: https://fly.io/apps/geanimusicboard
    Hostname: geanimusicboard.fly.dev
    Set secrets on geanimusicboard: APP_KEY
    Wrote config file fly.toml

    ? Would you like to deploy now? Yes


    $ flyctl deploy
      ：
    （中略）
     1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 1 total, 1 passing]
    --> v0 deployed successfully



    $ fly secrets set APP_DEBUG=true
    
    Update available 0.0.487 -> v0.0.492.
    Run "fly version update" to upgrade.
    Release v1 created
    ==> Monitoring deployment
    Logs: https://fly.io/apps/geanimusicboard/monitoring
    
     1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 1 total, 1 passing]
    --> v1 deployed successfully



    $ flyctl postgres create
    
    Update available 0.0.487 -> v0.0.492.
    Run "flyctl version update" to upgrade.
    ? Choose an app name (leave blank to generate one): ge-ani-musicbord-db
    automatically selected personal organization: （任意）
    Some regions require a paid plan (fra, maa).
    See https://fly.io/plans to set up a plan.
    
    ? Select region: Tokyo, Japan (nrt)
    ? Select configuration: Development - Single node, 1x shared CPU, 256MB RAM, 1GB disk
    Creating postgres cluster in organization personal
    Creating app...
    Setting secrets on app ge-ani-musicbord-db...
    Provisioning 1 of 1 machines with image flyio/postgres-flex:15.2@sha256:8e00d751bb9811bc8511d7129db2cc5a515449cf4a7def8f1d60faacb2be91c6
    Waiting for machine to start...
    Machine 91857272a5e383 is created
    ==> Monitoring health checks
      Waiting for 91857272a5e383 to become healthy (started, 3/3)
    
    Postgres cluster ge-ani-musicbord-db created
      Username:    postgres
      Password:    xxxxxxxxxxxxxxx
      Hostname:    ge-ani-musicbord-db.internal
      Flycast:     fdaa:x:xxx:x:x::x
      Proxy port:  xxxx
      Postgres port:  xxxx
      Connection string: postgres://postgres:xxxxxxxxxxxxxxx@ge-ani-musicbord-db.flycast:xxxx
    
    Save your credentials in a secure place -- you won't be able to see them again!
    
    Connect to postgres
    Any app within the （任意） organization can connect to this Postgres using the above connection string
    
    Now that you've set up Postgres, here's what you need to understand: https://fly.io/docs/postgres/getting-started/what-you-should-know/



    $ flyctl postgres attach ge-ani-musicbord-db -a geanimusicboard

    Update available 0.0.487 -> v0.0.492.
    Run "flyctl version update" to upgrade.
    Checking for existing attachments
    Registering attachment
    Creating database
    Creating user
    
    Postgres cluster ge-ani-musicbord-db is now attached to geanimusicboard
    The following secret was added to geanimusicboard:
      DATABASE_URL=postgres://geanimusicboard:d6UvAg9l2UqJjzC@ge-ani-musicbord-db.flycast:5432/geanimusicboard?sslmode=disable



    $ fly secrets set DB_CONNECTION=pgsql

    Update available 0.0.487 -> v0.0.492.
    Run "fly version update" to upgrade.
    Release v3 created
    ==> Monitoring deployment
    Logs: https://fly.io/apps/geanimusicboard/monitoring
    
     1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 1 total, 1 passing]
    --> v3 deployed successfully



    $ flyctl ssh console

    Update available 0.0.487 -> v0.0.492.
    Run "flyctl version update" to upgrade.
    Connecting to fdaa:1:49e:a7b:d829:69be:5b81:2... complete
    # cd /var/www/html
    # ls
    Dockerfile  README.md  app  artisan  bootstrap	composer.json  composer.lock  config  database	index.nginx-debian.html  package.json  phpunit.xml  public  resources  routes  server.php  storage  tests  vendor  webpack.mix.js
    # 
    # php artisan migrate
    **************************************
    *     Application In Production!     *
    **************************************
    
     Do you really wish to run this command? (yes/no) [no]:
     > yes
    
    Migration table created successfully.
    Migrating: 2014_10_12_000000_create_users_table
    Migrated:  2014_10_12_000000_create_users_table (0.03 seconds)
    Migrating: 2014_10_12_100000_create_password_resets_table
    Migrated:  2014_10_12_100000_create_password_resets_table (0.01 seconds)
    Migrating: 2019_08_19_000000_create_failed_jobs_table
    Migrated:  2019_08_19_000000_create_failed_jobs_table (0.01 seconds)
    Migrating: 2023_01_11_234631_create_posts_table
    Migrated:  2023_01_11_234631_create_posts_table (0.02 seconds)
    Migrating: 2023_02_11_152043_create_follow_users_table
    Migrated:  2023_02_11_152043_create_follow_users_table (0.04 seconds)
    # 
    # exit



    $ ls -al .env



    $ cat -n .env
    →　APP_DEBUGに注目



    $ flyctl ssh console

    Update available 0.0.487 -> v0.0.492.
    Run "flyctl version update" to upgrade.
    Connecting to fdaa:1:49e:a7b:d829:69be:5b81:2... complete
    # cd /var/www/html
    # ls
    Dockerfile  README.md  app  artisan  bootstrap	composer.json  composer.lock  config  database	index.nginx-debian.html  package.json  phpunit.xml  public  resources  routes  server.php  storage  tests  vendor  webpack.mix.js
    # 
    # php artisan migrate:fresh --seed
    **************************************
    *     Application In Production!     *
    **************************************
    
     Do you really wish to run this command? (yes/no) [no]:
     > yes
    
    Dropped all tables successfully.
    Migration table created successfully.
    Migrating: 2014_10_12_000000_create_users_table
    Migrated:  2014_10_12_000000_create_users_table (0.01 seconds)
    Migrating: 2014_10_12_100000_create_password_resets_table
    Migrated:  2014_10_12_100000_create_password_resets_table (0.01 seconds)
    Migrating: 2019_08_19_000000_create_failed_jobs_table
    Migrated:  2019_08_19_000000_create_failed_jobs_table (0.02 seconds)
    Migrating: 2023_01_11_234631_create_posts_table
    Migrated:  2023_01_11_234631_create_posts_table (0.03 seconds)
    Migrating: 2023_02_11_152043_create_follow_users_table
    Migrated:  2023_02_11_152043_create_follow_users_table (0.05 seconds)
    Seeding: UsersTableSeeder
    Seeded:  UsersTableSeeder (1.63 seconds)
    Seeding: PostsTableSeeder
    Seeded:  PostsTableSeeder (0.18 seconds)
    Seeding: FollowsTableSeeder
    Seeded:  FollowsTableSeeder (0.29 seconds)
    Database seeding completed successfully.
    # 
    # exit



■git操作
-

    $ git status
    
    On branch (対象のブランチ名)
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    	.dockerignore
    	.fly/
    	Dockerfile
    	fly.toml
    
    nothing added to commit but untracked files present (use "git add" to track)



    $ git add .
    
    $ git commit -m"ゲーアニ MusicBoard fly.ioへのデプロイ"

    $ git log

    [end]