168 lines
7.0 KiB
YAML
168 lines
7.0 KiB
YAML
name: Docker Build
|
|
run-name: ${{ github.actor }} run Actions
|
|
|
|
on:
|
|
workflow_call:
|
|
secrets:
|
|
ARGOCD_GIT_TOKEN:
|
|
required: false
|
|
description: 'Token for ArgoCD Git access'
|
|
ARGOCD_GIT_SSH_KEY:
|
|
required: true
|
|
description: 'SSH key for ArgoCD Git access'
|
|
inputs:
|
|
ssh_known_hosts:
|
|
required: false
|
|
type: string
|
|
default: "gitea.pinpod.ir ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDayM+ZPLQzaIS/m4xiM0w6aH8nbQYLvv7EMkVLC7gb83AJrr1nEX8z5ayt1Ed6GDMdniwdhyx9jZXagTDFwSb/p19pJ1dIThyI1Zap1aDzG6fxTOCMWqTOyEbvGTCcOuzmWloblqM8KMjrRfBP2dnRsmOCHYTOtjlDPOHvtruqbgyQjD3+1y1ico8U82+sE6N448/f6ytCPZMiAGNpk5DJomfCc34zuSSFeTpRiPZjJ2dNHUzebVG+V8jjqeDef1LlxAhZ7fgvhfzs1b7eI6pdh0zNCgmsFOuc38re4lrwyVK3BqJrp0w6ioA78FQ3bHVqPnN5U5FqH4eK2BzSOxfznw3+jki2/0gNcR+QuPEej5U4BIvJwfJ7C7XPaYvMFf1/s1wgIxFtpl1djIcWcU3H3nQ62qn30k5oMDWySYFm5ONB+tDVCsDtxHa5uMagaDa3SzeU+pdHrdPFdpXd4AH61SuZv3xbuij0TA9u5C30IKzBktbAxPtNDlry9HekrasNQAvYb5B4eVrLIPnSCIwwJrWMreX5q0ZhPin465q8bJN/IPvkHhRH4K3EWO4nIN+hpv56dETeUOF3xqeUZhdp/i0Q0WQMt5+5ruZjKiz31mAerXD74GUPVwn/euKKhwTX3W9E9FhH106+r7pSHObewIM5ZdtgpEmBecE5uFzi5Q=="
|
|
registry:
|
|
required: false
|
|
type: string
|
|
default: ${{ vars.REGISTERY_ADDRESS }}
|
|
debug:
|
|
required: false
|
|
type: boolean
|
|
default: false
|
|
argocd_repo_url:
|
|
required: false
|
|
type: string
|
|
default: ${{ github.repository_owner }}/argocd
|
|
readme:
|
|
required: false
|
|
type: string
|
|
default: |
|
|
# ${{ github.repository }} - ${{ github.ref_name }}
|
|
|
|
This directory contains the ArgoCD manifests for the ${{ github.repository }} repository on the ${{ github.ref_name }} branch.
|
|
|
|
## Repository Information
|
|
- Repository: ${{ github.repository }}
|
|
- Branch: ${{ github.ref_name }}
|
|
- URL: https://github.com/${{ github.repository }}/tree/${{ github.ref_name }}
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
|
|
- uses: rlespinasse/github-slug-action@v5
|
|
id: slug
|
|
|
|
- name: checkout argocd repo
|
|
uses: actions/checkout@v7
|
|
with:
|
|
repository: ${{ inputs.argocd_repo_url }}
|
|
# token: ${{ secrets.ARGOCD_GIT_TOKEN }}
|
|
ssh-key: ${{ secrets.ARGOCD_GIT_SSH_KEY }}
|
|
ssh-known-hosts: ${{ inputs.ssh_known_hosts }}
|
|
# path: argocd-repo
|
|
|
|
# - uses: imranismail/setup-kustomize@v2
|
|
# with:
|
|
# kustomize-version: '5.7.1'
|
|
# TODO: caching kustomize binary
|
|
|
|
- name: install kustomize
|
|
run: |
|
|
set -e -x # enable debugging
|
|
curl -sSL -o kustomize.tar.gz https://gitea.pinpod.ir/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.8.1/kustomize_v5.8.1_linux_amd64.tar.gz
|
|
tar -xzf kustomize.tar.gz
|
|
mv kustomize /usr/local/bin/kustomize
|
|
chmod +x /usr/local/bin/kustomize
|
|
|
|
- name: debug info
|
|
if: ${{ inputs.debug }}
|
|
run: |
|
|
echo "Repo URL is ${{ inputs.argocd_repo_url }}"
|
|
printenv
|
|
- name: Create path if not exists
|
|
run: |
|
|
set -e
|
|
set -x # enable debugging
|
|
printenv
|
|
# check if org exists
|
|
if [ -d "./manifests/${{env.GITHUB_REF_SLUG}}/${{env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL}}" ]; then
|
|
echo "Org directory exists"
|
|
else
|
|
echo "Org directory does not exist, creating..."
|
|
mkdir -p "./manifests/${{env.GITHUB_REF_SLUG}}/${{env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL}}"
|
|
fi
|
|
cd "./manifests/${{env.GITHUB_REF_SLUG}}/${{env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL}}"
|
|
# check if README.md exists
|
|
if [ -f "README.md" ]; then
|
|
echo "README.md file exists"
|
|
else
|
|
echo "README.md file does not exist, creating..."
|
|
echo "${{ inputs.readme }}" > README.md
|
|
fi
|
|
|
|
# check if path exists
|
|
if [ -d "./services" ]; then
|
|
echo "Path exists"
|
|
else
|
|
echo "Path does not exist, creating..."
|
|
mkdir -p "./services"
|
|
touch "./services/.gitkeep"
|
|
fi
|
|
- name: list files
|
|
if : ${{ inputs.debug }}
|
|
run: ls -laR ./manifests/${{env.GITHUB_REF_SLUG}}/${{env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL}}
|
|
|
|
- name: kustomize set image
|
|
run: |
|
|
set -e
|
|
if ${{ inputs.debug }}; then
|
|
set -x # enable debugging
|
|
printenv
|
|
fi
|
|
|
|
cd "./manifests/${{env.GITHUB_REF_SLUG}}/${{env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL}}"
|
|
|
|
echo "${{ inputs.readme }}" > README.md
|
|
echo "# Deployed image info" >> README.md
|
|
echo "Updating image to ${{ inputs.registry }}/${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}:sha-${{ github.sha }}" >> README.md
|
|
echo "" >> README.md
|
|
echo "Last updated at $(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> README.md
|
|
echo "" >> README.md
|
|
echo "commit: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}" >> README.md
|
|
|
|
if [ -f "kustomization.yaml" ]; then
|
|
echo "kustomization.yaml file exists, updating image..."
|
|
else
|
|
echo "kustomization.yaml file does not exist, creating..."
|
|
kustomize create .
|
|
fi
|
|
|
|
kustomize edit set image ${{ inputs.registry }}/${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}:latest=${{ inputs.registry }}/${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}:sha-${{ github.sha }}
|
|
kustomize edit set annotation \
|
|
app.io/version:"${{ github.sha }}" \
|
|
app.io/branch:"${{ github.ref_name }}" \
|
|
app.io/repository:"${{ github.repository }}" \
|
|
app.io/commit-origin:"${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}"
|
|
- name: kustomize debug
|
|
if: ${{ inputs.debug }}
|
|
run: |
|
|
set -e
|
|
set -x # enable debugging
|
|
cd "./manifests/${{env.GITHUB_REF_SLUG}}/${{env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL}}"
|
|
cat README.md
|
|
cat kustomization.yaml
|
|
- name: Commit and push changes
|
|
run: |
|
|
set -e
|
|
if ${{ inputs.debug }}; then
|
|
set -x # enable debugging
|
|
printenv
|
|
fi
|
|
cd "./manifests/${{env.GITHUB_REF_SLUG}}/${{env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL}}"
|
|
git config --global user.name "github-actions[bot]"
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
git add .
|
|
git commit -m "Update ArgoCD manifests by ${{ github.actor }}" -m "Repository: ${{ github.repository }}
|
|
Actor: ${{ github.actor }}
|
|
Commit: ${{ github.sha }}
|
|
Branch: ${{ github.ref_name }}" \
|
|
|| echo "No changes to commit"
|
|
|
|
|
|
git push origin main || echo "No changes to push" |