mirror of
https://gitea.pinpod.ir/pinwar/gh-actions.git
synced 2026-09-15 06:22:27 +00:00
add argocd
This commit is contained in:
150
.github/workflows/argocd.yaml
vendored
Normal file
150
.github/workflows/argocd.yaml
vendored
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
name: Docker Build
|
||||||
|
run-name: ${{ github.actor }} run Actions
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
secrets:
|
||||||
|
ARGOCD_GIT_TOKEN:
|
||||||
|
required: true
|
||||||
|
description: 'Token for ArgoCD Git access'
|
||||||
|
inputs:
|
||||||
|
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@v4
|
||||||
|
with:
|
||||||
|
repository: ${{ inputs.argocd_repo_url }}
|
||||||
|
token: ${{ secrets.ARGOCD_GIT_TOKEN }}
|
||||||
|
- uses: imranismail/setup-kustomize@v2
|
||||||
|
with:
|
||||||
|
kustomize-version: '5.7.1'
|
||||||
|
|
||||||
|
- 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_REPOSITORY_NAME_PART_SLUG_URL}}/${{env.GITHUB_REF_SLUG}}" ]; then
|
||||||
|
echo "Org directory exists"
|
||||||
|
else
|
||||||
|
echo "Org directory does not exist, creating..."
|
||||||
|
mkdir -p "./manifests/${{env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL}}/${{env.GITHUB_REF_SLUG}}"
|
||||||
|
fi
|
||||||
|
cd "./manifests/${{env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL}}/${{env.GITHUB_REF_SLUG}}"
|
||||||
|
# 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_REPOSITORY_NAME_PART_SLUG_URL}}/${{env.GITHUB_REF_SLUG}}
|
||||||
|
|
||||||
|
- name: kustomize set image
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
if ${{ inputs.debug }}; then
|
||||||
|
set -x # enable debugging
|
||||||
|
printenv
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "./manifests/${{env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL}}/${{env.GITHUB_REF_SLUG}}"
|
||||||
|
|
||||||
|
echo "${{ inputs.readme }}" > README.md
|
||||||
|
echo "# Deployed image info" >> README.md
|
||||||
|
echo "Updating image to ${{ inputs.registry }}/${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_CS }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL_CS }}: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_CS }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL_CS }}:latest=${{ inputs.registry }}/${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_CS }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL_CS }}:sha-${{ github.sha }}
|
||||||
|
kustomize edit set namespace ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL_CS }}-${{ env.GITHUB_REF_SLUG }}
|
||||||
|
kustomize edit add annotation deployed-by "github-actions[bot]"
|
||||||
|
kustomize edit add annotation commit-sha "${{ github.sha }}"
|
||||||
|
kustomize edit add annotation branch "${{ github.ref_name }}"
|
||||||
|
kustomize edit add annotation repository "${{ github.repository }}"
|
||||||
|
kustomize edit add annotation 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_REPOSITORY_NAME_PART_SLUG_URL}}/${{env.GITHUB_REF_SLUG}}"
|
||||||
|
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_REPOSITORY_NAME_PART_SLUG_URL}}/${{env.GITHUB_REF_SLUG}}"
|
||||||
|
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 HEAD:${{ github.ref_name }} || echo "No changes to push"
|
||||||
21
.github/workflows/docker.yaml
vendored
21
.github/workflows/docker.yaml
vendored
@@ -6,11 +6,15 @@ on:
|
|||||||
secrets:
|
secrets:
|
||||||
REGISTERY_USER:
|
REGISTERY_USER:
|
||||||
required: true
|
required: true
|
||||||
description: 'Username for Docker registry'
|
description: "Username for Docker registry"
|
||||||
REGISTERY_PASSWORD:
|
REGISTERY_PASSWORD:
|
||||||
required: true
|
required: true
|
||||||
description: 'Password for Docker registry'
|
description: "Password for Docker registry"
|
||||||
inputs:
|
inputs:
|
||||||
|
Debug:
|
||||||
|
required: false
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
Dockerfile:
|
Dockerfile:
|
||||||
required: false
|
required: false
|
||||||
type: string
|
type: string
|
||||||
@@ -29,23 +33,24 @@ on:
|
|||||||
type=semver,pattern={{major}}.{{minor}}
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
type=sha
|
type=sha
|
||||||
type=sha,format=long
|
type=sha,format=long
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
- uses: rlespinasse/github-slug-action@v5
|
- uses: rlespinasse/github-slug-action@v5
|
||||||
id: slug
|
id: slug
|
||||||
- name: debug info
|
- name: debug info
|
||||||
|
if: ${{ inputs.Debug }}
|
||||||
run: |
|
run: |
|
||||||
printenv
|
printenv
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v2
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: docker/setup-qemu-action@v2
|
- uses: docker/setup-qemu-action@v2
|
||||||
- uses: docker/login-action@v2
|
- uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: ${{ inputs.registry }}
|
registry: ${{ inputs.registry }}
|
||||||
username: ${{ secrets.REGISTERY_USER }}
|
username: ${{ secrets.REGISTERY_USER }}
|
||||||
password: ${{ secrets.REGISTERY_PASSWORD }}
|
password: ${{ secrets.REGISTERY_PASSWORD }}
|
||||||
- name: echo image name
|
- name: echo image name
|
||||||
@@ -55,9 +60,9 @@ jobs:
|
|||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: ${{ inputs.registry }}/${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_CS }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL_CS }}
|
images: ${{ inputs.registry }}/${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_CS }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL_CS }}
|
||||||
tags: ${{ inputs.tags }}
|
tags: ${{ inputs.tags }}
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ${{ inputs.Dockerfile }}
|
file: ${{ inputs.Dockerfile }}
|
||||||
@@ -66,4 +71,4 @@ jobs:
|
|||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
annotations: ${{ steps.meta.outputs.annotations }}
|
annotations: ${{ steps.meta.outputs.annotations }}
|
||||||
|
|||||||
14
.github/workflows/test-argocd.yaml
vendored
Normal file
14
.github/workflows/test-argocd.yaml
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
name: ArgoCD Deployment
|
||||||
|
run-name: ${{ github.actor }} run Actions 🚀
|
||||||
|
|
||||||
|
on:
|
||||||
|
- push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
argocd:
|
||||||
|
uses: ./.github/workflows/argocd.yaml
|
||||||
|
with:
|
||||||
|
debug: true
|
||||||
|
secrets:
|
||||||
|
ARGOCD_GIT_TOKEN: ${{ secrets.ARGOCD_GIT_TOKEN }}
|
||||||
|
|
||||||
22
.github/workflows/test-full.yaml
vendored
Normal file
22
.github/workflows/test-full.yaml
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
name: full CI
|
||||||
|
run-name: ${{ github.actor }} run Actions 🚀
|
||||||
|
|
||||||
|
on:
|
||||||
|
- push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
uses: ./.github/workflows/docker.yaml
|
||||||
|
with:
|
||||||
|
registry: ${{ vars.REGISTERY_ADDRESS }}
|
||||||
|
secrets:
|
||||||
|
REGISTERY_USER: ${{ secrets.REGISTERY_USER }}
|
||||||
|
REGISTERY_PASSWORD: ${{ secrets.REGISTERY_PASSWORD }}
|
||||||
|
argocd:
|
||||||
|
uses: ./.github/workflows/argocd.yaml
|
||||||
|
needs: docker
|
||||||
|
with:
|
||||||
|
debug: true
|
||||||
|
secrets:
|
||||||
|
ARGOCD_GIT_TOKEN: ${{ secrets.ARGOCD_GIT_TOKEN }}
|
||||||
|
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1 +1,4 @@
|
|||||||
.act
|
.act
|
||||||
|
.vars
|
||||||
|
.secrets
|
||||||
|
.env
|
||||||
Reference in New Issue
Block a user