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 dans la documentation Stackhero

Stackhero offre une plateforme Docker cloud CaaS (Containers as a Service) prête à l’emploi, conçue pour des déploiements de containers rapides et fiables :

  • Déployez en production avec un simple docker-compose up. Aucune configuration supplémentaire requise : démarrez simplement vos containers.
  • Choisissez votre propre nom de domaine, automatiquement sécurisé avec HTTPS (par exemple : https://api.votre-entreprise.com, https://www.votre-entreprise.com ou https://backoffice.votre-entreprise.com).
  • Profitez de performances élevées et d’une sécurité robuste sur une infrastructure privée et dédiée.
  • Appliquez les mises à jour en un clic pour une maintenance simple et sans tracas.

Vos containers peuvent être en production en environ cinq minutes. Stackhero prend en charge l’infrastructure, les mises à jour et la sécurité pour vous permettre de vous concentrer sur la livraison de vos applications. Pour en savoir plus sur l’hébergement cloud Docker CaaS.

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.