update_config #5850
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: Update Config | |
on: | |
repository_dispatch: | |
types: | |
- update_config | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Out The Repository | |
uses: actions/checkout@v2 | |
- name: Set Payload Aliases | |
id: set_payload | |
run: | | |
echo "service_name=${{ github.event.client_payload.service_name }}" >> $GITHUB_ENV | |
echo "service_prefix=${{ github.event.client_payload.service_prefix }}" >> $GITHUB_ENV | |
echo "image_tag=${{ github.event.client_payload.image_tag }}" >> $GITHUB_ENV | |
echo "environment=${{ github.event.client_payload.environment }}" >> $GITHUB_ENV | |
echo "service_type=${{ github.event.client_payload.service_type }}" >> $GITHUB_ENV | |
echo "service_domain=${{ github.event.client_payload.service_domain }}" >> $GITHUB_ENV | |
echo "service_port=${{ github.event.client_payload.service_port }}" >> $GITHUB_ENV | |
echo "critical_service=${{ github.event.client_payload.critical_service }}" >> $GITHUB_ENV | |
echo "private_service=${{ github.event.client_payload.private_service }}" >> $GITHUB_ENV | |
- name: Pull Commit | |
run: git pull | |
- name: Get club name | |
id: get-club-name | |
run: | | |
url="https://prod-server.xquare.app/project-secret-manager/club\ | |
?project-name=${{ env.service_name }}" | |
response=$(curl -X GET $url) | |
echo "club_name=$response" >> $GITHUB_ENV | |
- name: Sync Container Status to infra server | |
continue-on-error: true | |
shell: bash | |
run: | | |
url="https://xquare-infra-backend.xquare.app/v1/container/sync?deploy_name=${{ env.service_name }}&environment=${{ env.environment }}&domain=${{ env.service_domain }}" | |
curl -X POST $url | |
- name: Get config file path | |
id: config-file | |
working-directory: ${{ github.workspace }} | |
run: | | |
config_file_dir="./charts/apps/resource/${{ env.environment }}/${{ env.service_name }}-${{ env.service_type }}" | |
mkdir -p "$config_file_dir" | |
config_file_path="$config_file_dir/resource.yaml" | |
if [ ! -e "$config_file_path" ]; then | |
echo "config file is not exists" | |
touch "$config_file_path" | |
yq eval ".config.volume.name = null | \ | |
.config.volume.mountPath = null | \ | |
.config.volume.secretName = null | \ | |
.config.serviceAccount = null | \ | |
.config.replicas = 1 | \ | |
.config.clubName = \"${{ env.club_name }}\"" -i $config_file_path | |
else | |
echo "config file is exists" | |
fi | |
echo "config_file_path=$config_file_path" >> $GITHUB_OUTPUT | |
- name: Use yq to modify Config file | |
working-directory: ${{ github.workspace }} | |
run: | | |
domain='' | |
prefix='' | |
if [ -n "${{ env.service_domain }}" ] && [ "${{ env.service_domain }}" != "null" ]; then | |
domain='.config.domain = "${{ env.service_domain }}"' | |
else | |
domain='.config.domain = null' | |
fi | |
if [ -n "${{ env.service_prefix }}" ] && [ "${{ env.service_prefix }}" != "null" ]; then | |
prefix='.config.prefix = "${{ env.service_prefix }}"' | |
else | |
prefix='.config.prefix = null' | |
fi | |
yq eval -i ".config.serviceName = \"${{ env.service_name }}\" | \ | |
.config.imageTag = \"${{ env.image_tag }}\" | \ | |
.config.containerPort = ${{ env.service_port }} | \ | |
.config.environment = \"${{ env.environment }}\" | \ | |
.config.type = \"${{ env.service_type }}\" | \ | |
.config.critical_service = \"${{ env.critical_service }}\" | \ | |
.config.private_service = \"${{ env.private_service }}\" | \ | |
$domain | \ | |
$prefix" -i ${{ steps.config-file.outputs.config_file_path }} | |
- name: Commit The New Image Reference | |
if: ${{ env.service_name && env.service_prefix && env.image_tag && env.environment && env.service_type }} | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: "release :: ${{ env.service_name }}-${{ env.service_type }}-${{ env.environment }}: Deploy new image ${{ env.image_tag }}" | |
branch: master | |
commit_options: '--no-verify --signoff' | |
repository: . | |
commit_user_name: XQUARE GitOps Bot | |
commit_user_email: [email protected] | |
commit_author: XQUARE GitOps Bot <[email protected]> |