Docker: Configurer le workflow GitHub Actions

Cette documentation fait partie du guide Déployer avec GitHub Actions. Consultez le guide complet ici : Apprenez comment déployer vos conteneurs Docker à l'aide de GitHub Actions.

👋 Bienvenue sur la documentation de Stackhero !

Stackhero propose une solution Docker cloud CaaS (Containers as a Service) prête à l'emploi offrant de nombreux avantages, notamment :

  • Déployez facilement vos containers en production avec un simple docker-compose up.
  • Nom de domaine personnalisable sécurisé avec HTTPS (par exemple, https://api.votre-entreprise.com, https://www.votre-entreprise.com, https://backoffice.votre-entreprise.com).
  • Performance optimale et sécurité robuste grâce à une VM privée et dédiée.
  • Mises à jour simplifiées en un clic.

Gagnez du temps et simplifiez-vous la vie : il suffit de 5 minutes pour essayer la solution d'hébergement cloud Docker CaaS de Stackhero et déployer vos containers en production !

Sur votre machine locale, placez-vous dans votre dépôt Git et créez un dossier nommé .github/workflows. Dans ce dossier, créez un fichier nommé deploy-to-stackhero.yml avec le contenu suivant :

# 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 }}

Vous pouvez valider vos modifications avec :

git add -A .
git commit -m "Add GitHub Actions to deploy to Stackhero"

Pour créer une branche production, exécutez :

git checkout -b production

Puis poussez votre branche production sur GitHub :

git push --set-upstream origin production

Une fois votre code poussé, GitHub Actions le déploiera automatiquement sur votre instance Stackhero de production. Vous pouvez suivre la progression du déploiement dans l'onglet Actions de votre projet GitHub.

GitHub Actions ayant déployé en productionGitHub Actions ayant déployé en production

Voilà, votre configuration est maintenant prête pour déployer automatiquement votre code en production avec GitHub Actions.