Docker Build and Push #1310
This file contains hidden or 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: Docker Build and Push | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: "0 0 * * *" # This will run daily at midnight | |
| jobs: | |
| Test: | |
| runs-on: self-hosted-linux | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # Uncomment if you want to do a Hugo test build or HTML validation | |
| # - name: HUGO test build | |
| # run: | | |
| # docker run --rm -v $(pwd)/blog/:/src -w /src thegeeklab/hugo:latest --panicOnWarning --minify --gc --cleanDestinationDir --destination public --baseURL http://localhost | |
| # - name: html-validation | |
| # run: | | |
| # docker run --rm -v $(pwd)/blog/:/src -w /src thegeeklab/vnu vnu --skip-non-html --errors-only --filterfile .vnuignore public/ | |
| - name: Checking for expired content | |
| run: | | |
| docker run --rm -v $(pwd)/blog/:/src -w /src thegeeklab/hugo:0.122 list expired | |
| Build: | |
| runs-on: self-hosted-linux | |
| needs: Test | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Docker build and push | |
| run: | | |
| docker buildx build \ | |
| --platform linux/amd64 \ | |
| --pull \ | |
| --build-arg VERSION="v${{ github.run_number }}" \ | |
| --build-arg GIT_COMMIT="${{ github.sha }}" \ | |
| --build-arg BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')" \ | |
| --cache-from supporttools/website:latest \ | |
| -t supporttools/website:v${{ github.run_number }} \ | |
| -t supporttools/website:latest \ | |
| --push \ | |
| -f Dockerfile . | |
| Publish: | |
| runs-on: self-hosted-linux | |
| needs: Build | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install gettext | |
| run: | | |
| sudo apt-get update && sudo apt-get install -y gettext | |
| - name: Set up Helm | |
| uses: azure/setup-helm@v4.2.0 | |
| - name: Helm Lint | |
| run: helm lint charts/website/ | |
| - name: Package Helm chart | |
| run: | | |
| export CHART_VERSION="v${{ github.run_number }}" | |
| export APP_VERSION="v${{ github.run_number }}" | |
| export IMAGE_TAG="v${{ github.run_number }}" | |
| echo "CHART_VERSION=${CHART_VERSION}" | |
| echo "APP_VERSION=${APP_VERSION}" | |
| echo "IMAGE_TAG=${IMAGE_TAG}" | |
| envsubst < charts/website/Chart.yaml.template > charts/website/Chart.yaml | |
| envsubst < charts/website/values.yaml.template > charts/website/values.yaml | |
| helm package charts/website --destination helm/repo | |
| - name: Checkout helm-chart repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: SupportTools/helm-chart | |
| path: helm-chart | |
| token: ${{ secrets.BOT_TOKEN }} | |
| - name: Configure Git | |
| run: | | |
| git config --global user.email "github-action@users.noreply.github.com" | |
| git config --global user.name "GitHub Action" | |
| - name: Update Helm repository | |
| run: | | |
| cp helm/repo/website-*.tgz helm-chart/ | |
| cd helm-chart | |
| helm repo index . --url https://charts.support.tools/ | |
| git add . | |
| git commit -m "Update Helm chart for support.tools" | |
| git push | |
| Deploy-NonProd: | |
| runs-on: self-hosted-linux | |
| needs: Publish | |
| strategy: | |
| max-parallel: 1 | |
| matrix: | |
| environment: [mst, dev, qas, tst] | |
| outputs: | |
| synccdn_needed: ${{ steps.check-sync-cdn.outputs.synccdn }} | |
| environment: ${{ matrix.environment }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup kubectl | |
| uses: azure/setup-kubectl@v4 | |
| - name: Setup Kubeconfig | |
| run: | | |
| echo "${{ secrets.KUBECONFIG_DEV }}" | base64 -d > kubeconfig | |
| chmod 600 kubeconfig | |
| - name: Deploy ArgoCD Project | |
| run: kubectl --kubeconfig kubeconfig apply -f argocd/project.yaml | |
| - name: Deploy Environment - ${{ matrix.environment }} | |
| run: | | |
| ENVIRONMENT=${{ matrix.environment }} | |
| CHART_VERSION="v${{ github.run_number }}" | |
| # Check if application exists | |
| if kubectl --kubeconfig kubeconfig -n argocd get application supporttools-${ENVIRONMENT} &>/dev/null; then | |
| echo "ArgoCD Application 'supporttools-${ENVIRONMENT}' exists. Patching targetRevision to ${CHART_VERSION}." | |
| kubectl --kubeconfig kubeconfig -n argocd patch application "supporttools-${ENVIRONMENT}" \ | |
| --type merge \ | |
| -p "{\"spec\":{\"source\":{\"targetRevision\":\"${CHART_VERSION}\"}}}" | |
| else | |
| echo "ArgoCD Application 'supporttools-${ENVIRONMENT}' does not exist. Creating..." | |
| sed "s/CHARTVERSION/${CHART_VERSION}/g" argocd/${ENVIRONMENT}.yaml \ | |
| | kubectl --kubeconfig kubeconfig -n argocd apply -f - | |
| fi | |
| - name: Wait for Deployment to Stabilize | |
| run: | | |
| MAX_TRIES=30 | |
| SLEEP_TIME=10 | |
| COUNTER=0 | |
| while [ $COUNTER -lt $MAX_TRIES ]; do | |
| HEALTH_STATUS=$(kubectl --kubeconfig kubeconfig -n argocd get applications supporttools-${{ matrix.environment }} -o jsonpath='{.status.health.status}') | |
| echo "Current health status: $HEALTH_STATUS" | |
| if [ "$HEALTH_STATUS" = "Healthy" ]; then | |
| echo "Application is healthy." | |
| break | |
| fi | |
| echo "Waiting for application to become healthy..." | |
| sleep $SLEEP_TIME | |
| let COUNTER=COUNTER+1 | |
| done | |
| if [ $COUNTER -eq $MAX_TRIES ]; then | |
| echo "Application did not become healthy in time." | |
| exit 1 | |
| fi | |
| - name: Check if CDN Sync is needed | |
| id: check-sync-cdn | |
| run: | | |
| if [[ "${{ matrix.environment }}" == "qas" || "${{ matrix.environment }}" == "tst" || "${{ matrix.environment }}" == "stg" || "${{ matrix.environment }}" == "prd" ]]; then | |
| echo "synccdn=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "synccdn=false" >> $GITHUB_OUTPUT | |
| fi | |
| Deploy-Prod: | |
| runs-on: self-hosted-linux | |
| needs: Deploy-NonProd | |
| strategy: | |
| max-parallel: 1 | |
| matrix: | |
| environment: [stg, prd] | |
| outputs: | |
| synccdn_needed: ${{ steps.check-sync-cdn.outputs.synccdn }} | |
| environment: ${{ matrix.environment }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup kubectl | |
| uses: azure/setup-kubectl@v4 | |
| - name: Setup Kubeconfig | |
| run: | | |
| echo "${{ secrets.KUBECONFIG_PROD }}" | base64 -d > kubeconfig | |
| chmod 600 kubeconfig | |
| - name: Deploy ArgoCD Project | |
| run: kubectl --kubeconfig kubeconfig apply -f argocd/project.yaml | |
| - name: Deploy Environment - ${{ matrix.environment }} | |
| run: | | |
| ENVIRONMENT=${{ matrix.environment }} | |
| CHART_VERSION="v${{ github.run_number }}" | |
| # Check if application exists | |
| if kubectl --kubeconfig kubeconfig -n argocd get application supporttools-${ENVIRONMENT} &>/dev/null; then | |
| echo "ArgoCD Application 'supporttools-${ENVIRONMENT}' exists. Patching targetRevision to ${CHART_VERSION}." | |
| kubectl --kubeconfig kubeconfig -n argocd patch application "supporttools-${ENVIRONMENT}" \ | |
| --type merge \ | |
| -p "{\"spec\":{\"source\":{\"targetRevision\":\"${CHART_VERSION}\"}}}" | |
| else | |
| echo "ArgoCD Application 'supporttools-${ENVIRONMENT}' does not exist. Creating..." | |
| sed "s/CHARTVERSION/${CHART_VERSION}/g" argocd/${ENVIRONMENT}.yaml \ | |
| | kubectl --kubeconfig kubeconfig -n argocd apply -f - | |
| fi | |
| - name: Wait for Deployment to Stabilize | |
| run: | | |
| MAX_TRIES=30 | |
| SLEEP_TIME=10 | |
| COUNTER=0 | |
| while [ $COUNTER -lt $MAX_TRIES ]; do | |
| HEALTH_STATUS=$(kubectl --kubeconfig kubeconfig -n argocd get applications supporttools-${{ matrix.environment }} -o jsonpath='{.status.health.status}') | |
| echo "Current health status: $HEALTH_STATUS" | |
| if [ "$HEALTH_STATUS" = "Healthy" ]; then | |
| echo "Application is healthy." | |
| break | |
| fi | |
| echo "Waiting for application to become healthy..." | |
| sleep $SLEEP_TIME | |
| let COUNTER=COUNTER+1 | |
| done | |
| if [ $COUNTER -eq $MAX_TRIES ]; then | |
| echo "Application did not become healthy in time." | |
| exit 1 | |
| fi | |
| - name: Check if CDN Sync is needed | |
| id: check-sync-cdn | |
| run: | | |
| if [[ "${{ matrix.environment }}" == "qas" || "${{ matrix.environment }}" == "tst" || "${{ matrix.environment }}" == "stg" || "${{ matrix.environment }}" == "prd" ]]; then | |
| echo "synccdn=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "synccdn=false" >> $GITHUB_OUTPUT | |
| fi | |
| # Sync-CDN: | |
| # runs-on: ubuntu-latest | |
| # needs: Deploy | |
| # if: needs.Deploy.outputs.synccdn_needed == 'true' | |
| # steps: | |
| # - name: Checkout repository | |
| # uses: actions/checkout@v3 | |
| # with: | |
| # fetch-depth: 0 # Fetch all history for proper change detection | |
| # - name: Install AWS CLI | |
| # run: | | |
| # curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
| # unzip awscliv2.zip | |
| # sudo ./aws/install | |
| # aws --version | |
| # - name: Sync to Wasabi S3 bucket | |
| # env: | |
| # AWS_ACCESS_KEY_ID: ${{ secrets.WASABI_ACCESS_KEY }} | |
| # AWS_SECRET_ACCESS_KEY: ${{ secrets.WASABI_SECRET_KEY }} | |
| # AWS_REGION: us-central-1 | |
| # run: | | |
| # echo "Starting sync of cdn.support.tools to Wasabi for environment ${{ needs.Deploy.outputs.environment }}" | |
| # aws s3 sync ./cdn.support.tools/ s3://cdn.support.tools/ \ | |
| # --endpoint-url=https://s3.us-central-1.wasabisys.com \ | |
| # --exclude ".git/*" \ | |
| # --acl public-read | |
| # echo "Sync completed successfully" |