Docker: GitHub Actions ワークフローの設定
このドキュメントはGitHub Actions でデプロイするガイドの一部です。完全なガイドはこちらからご覧いただけます:GitHub Actions を使って Docker コンテナをデプロイする方法。
👋 Stackheroのドキュメントへようこそ!
Stackheroは、DockerクラウドCaaS (Containers as a Service) の即時利用可能なソリューションを提供し、多くの利点があります。例えば:
docker-compose upだけでコンテナを簡単に本番環境にデプロイ。- HTTPSで保護されたカスタマイズ可能なドメイン名(例: https://api.your-company.com, https://www.your-company.com, https://backoffice.your-company.com)。
- プライベートで専用のVMによる最適なパフォーマンスと強力なセキュリティ。
- ワンクリックでの簡単なアップデート。
時間を節約し、生活を簡素化:StackheroのDocker CaaSクラウドホスティング ソリューションを試して、コンテナを本番環境にデプロイするのに5分しかかかりません!
ローカルマシンで Git リポジトリに移動し、.github/workflows ディレクトリを作成します。その中に deploy-to-stackhero.yml というファイルを作成し、以下の内容を記述します:
# File: .github/workflows/deploy-to-stackhero.yml
name: Deploy to Stackhero
description: Deploy branch "${{ github.ref_name }}" to Stackhero
on:
push:
# These branches trigger the deploy action on push.
# Be sure to create an environment matching the branch name in GitHub (under Settings > Environments).
# Then add the secret STACKHERO_CERTIFICATES_PASSWORD and variable STACKHERO_ENDPOINT in that environment.
branches: [ "production", "staging" ]
jobs:
Deploy:
environment: ${{ github.ref_name }}
runs-on: ubuntu-latest
steps:
- uses: stackhero-io/github-actions-deploy-docker-containers-to-stackhero@v1
with:
# The secret STACKHERO_CERTIFICATES_PASSWORD and the variable STACKHERO_ENDPOINT should be defined in the corresponding branch environment on GitHub.
certificates_password: ${{ secrets.STACKHERO_CERTIFICATES_PASSWORD }}
endpoint: ${{ vars.STACKHERO_ENDPOINT }}
# deployment_command is optional. You can use it if you need to customize the Docker Compose command.
deployment_command: ${{ vars.STACKHERO_DEPLOY_COMMAND }}
変更をコミットするには、以下のコマンドを実行します:
git add -A .
git commit -m "Add GitHub Actions to deploy to Stackhero"
本番ブランチを作成するには、次のコマンドを実行します:
git checkout -b production
そして、本番ブランチを GitHub にプッシュします:
git push --set-upstream origin production
コードをプッシュすると、GitHub Actions が自動的に本番 Stackhero インスタンスへデプロイします。デプロイの進捗は GitHub プロジェクトの Actions タブで確認できます。
本番環境にデプロイされた GitHub Actions
これで、GitHub Actions を使った本番環境への自動デプロイが完了です。