Deploy production #1289
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy production | |
on: | |
workflow_dispatch: ~ | |
schedule: | |
- cron: '30 7 * * 1,2,3,4,5' # At 08:30 (UTC, => 08:30 / 09:30 in Europe/Paris depending on the DST), each day of the week. | |
push: | |
branches: | |
- master | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build-production: | |
name: '🚧 Build 🚀' | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
environment: | |
name: production | |
url: ${{ vars.WEBSITE_URL }} | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: 'Checkout' | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# https://github.com/actions/setup-node | |
- name: 'Setup node' | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .nvmrc | |
cache: 'npm' | |
- name: 'Setup PHP' | |
uses: shivammathur/setup-php@v2 | |
with: | |
coverage: "none" | |
ini-values: "memory_limit=-1" | |
php-version: "8.3" | |
- name: 'Cache resized images' | |
uses: actions/cache@v4 | |
with: | |
path: public/resized | |
key: resized-images-${{ github.workflow }}-${{ secrets.CACHE_VERSION }} | |
- name: 'Determine composer cache directory' | |
id: composer-cache | |
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
- name: 'Cache composer dependencies' | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: ${{ runner.os }}-composer- | |
- name: 'Install dependencies' | |
run: | | |
echo "::group::composer install" | |
composer install --no-progress --ansi | |
echo "::endgroup::" | |
echo "::group::npm install" | |
npm install --color=always --no-progress --no-audit --no-fund | |
echo "::endgroup::" | |
- name: 'Warmup' | |
run: | | |
echo "::group::warmup production env" | |
npx encore production --color | |
bin/console cache:clear --ansi | |
bin/console cache:warmup --ansi | |
echo "::endgroup::" | |
env: | |
APP_ENV: prod | |
- name: 'Build static site' | |
run: | | |
bin/console stenope:build --no-interaction -vv --ansi --ignore-content-not-found | |
env: | |
APP_ENV: prod | |
ROUTER_DEFAULT_URI: ${{ vars.WEBSITE_URL }} | |
INCLUDE_SAMPLES: 0 | |
SHOW_UNPUBLISHED_ARTICLES: 0 | |
MATOMO_ID: ${{ vars.MATOMO_ID }} | |
- name: 'Login to GitHub Container Registry' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: elao-tools | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: 'Build and push the Docker image for website prod' | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: kubernetes/Dockerfile | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: | | |
ghcr.io/elao/website:latest | |
deploy-helm: | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 5 | |
needs: [build-production] | |
steps: | |
- name: 'Set the Kubernetes context' | |
uses: azure/k8s-set-context@v4 | |
with: | |
method: kubeconfig | |
kubeconfig: $${{ secrets.KUBERNETES_KUBECONFIG }} | |
context: kubernetes-admin@elao_argon-website-prod | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- name: 'Render charts website' | |
uses: azure/[email protected] | |
id: bake_website | |
with: | |
renderEngine: helm | |
helmChart: kubernetes/charts/website | |
helm-version: latest | |
silent: false | |
- name: 'Deploy to the Kubernetes cluster' | |
uses: azure/k8s-deploy@v5 | |
with: | |
action: deploy | |
force: true | |
namespace: website-prod | |
manifests: ${{ steps.bake_website.outputs.manifestsBundle }} | |
pull-images: false | |
deploy-image: | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 5 | |
needs: [deploy-helm] | |
steps: | |
- name: 'Set the Kubernetes context' | |
uses: azure/k8s-set-context@v4 | |
with: | |
method: kubeconfig | |
kubeconfig: $${{ secrets.KUBERNETES_KUBECONFIG }} | |
context: kubernetes-admin@elao_argon-website-prod | |
- uses: azure/setup-kubectl@v4 | |
name: Setup kubectl | |
with: | |
version: v1.28.2 | |
- name: 'Rollout deployment website' | |
run: | | |
kubectl rollout restart deployment/website --namespace website-prod |