Docker: Omgevingsvariabelen gebruiken in docker-compose.yml
Deze documentatie maakt deel uit van de Deployen met GitHub Actions-gids. Bekijk de volledige gids hier: Leer hoe u uw Docker-containers kunt deployen met GitHub Actions.
Welkom bij de Stackhero-documentatie
Stackhero biedt een gebruiksklaar Docker cloud CaaS (Containers as a Service) platform, ontworpen voor snelle en betrouwbare containerdeployments:
- Zet uw containers direct in productie met slechts één
docker-compose up. Er is geen extra configuratie nodig: start gewoon uw containers.- Kies uw eigen domeinnaam, automatisch beveiligd met HTTPS (bijvoorbeeld: https://api.uw-bedrijf.com, https://www.uw-bedrijf.com of https://backoffice.uw-bedrijf.com).
- Profiteer van hoge prestaties en sterke beveiliging op een privé, dedicated infrastructuur.
- Voer updates uit met één klik voor eenvoudige, moeiteloze onderhoud.
Uw containers kunnen binnen ongeveer vijf minuten live in productie zijn. Stackhero beheert de infrastructuur, updates en beveiliging voor u, zodat u zich kunt richten op het leveren van uw applicaties. Lees meer over Docker CaaS cloud hosting.
U kunt omgevingsvariabelen definiëren in uw GitHub-project die beschikbaar zijn in uw docker-compose.yml-bestand. Dit is erg handig als u wilt deployen naar verschillende domeinen (bijvoorbeeld staging.my-company.com voor staging en my-company.com voor productie).
- Ga in GitHub naar Settings > Environments en maak een omgevingsvariabele aan met de naam
WEBSITE_DOMAIN. - Stel voor de staging-omgeving
WEBSITE_DOMAINin op "staging.my-company.com". - Stel voor de productie-omgeving
WEBSITE_DOMAINin op "my-company.com".
Werk vervolgens uw .github/workflows/deploy-to-stackhero.yml-bestand bij om de variabele WEBSITE_DOMAIN door te geven aan de Stackhero GitHub Action:
name: Deploy to Stackhero
description: Deploy branch "${{ github.ref_name }}" to Stackhero
on:
push:
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:
certificates_password: ${{ secrets.STACKHERO_CERTIFICATES_PASSWORD }}
endpoint: ${{ vars.STACKHERO_ENDPOINT }}
deployment_command: ${{ vars.STACKHERO_DEPLOY_COMMAND }}
env:
WEBSITE_DOMAIN: ${{ vars.WEBSITE_DOMAIN }}
Werk nu uw docker-compose.yml-bestand bij om de variabele WEBSITE_DOMAIN te gebruiken in plaats van een hardcoded domeinnaam:
services:
test:
image: nginx
labels:
- "traefik.enable=true"
- "traefik.http.routers.test.rule=Host(`${WEBSITE_DOMAIN}`)" # Gebruikt de omgevingsvariabele WEBSITE_DOMAIN als domeinnaam.
- "traefik.http.routers.test.tls.certresolver=letsencrypt"