Repository navigation
Update README.md (#33) #20
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: Prod Build Artifacts and Deploying | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| build-and-deploy: | |
| runs-on: self-hosted-prod | |
| steps: | |
| # Sanity check | |
| - name: Run | |
| run: | | |
| /usr/bin/docker images | |
| # When self-hosting this is necessary | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| # Parsing files list | |
| - name: List of changed files | |
| id: changed-files | |
| uses: tj-actions/changed-files@v39 | |
| - name: String to multiline | |
| id: convert | |
| run: | | |
| echo 'MULTILINE<<EOF' >> $GITHUB_ENV | |
| echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr " " "\n" >> $GITHUB_ENV | |
| echo 'EOF' >> $GITHUB_ENV | |
| # Applying only changed files | |
| - if: ${{ env.MULTILINE != '' }} | |
| name: Applying | |
| run: | | |
| for file in ${{ steps.changed-files.outputs.all_changed_files }}; do | |
| if [[ $file == */Dockerfile ]]; then | |
| echo "Building: $file" | |
| ### Exclusive for Github Actions Runner | |
| if [[ $file == runner/* ]]; then | |
| sed -i "s/<TOKEN>/${{ secrets.TOKEN }}/g;s/<ENV>/prod/g" $file | |
| sed -i "s/<CERT_ONE>/${{ secrets.CERT_ONE }}/g;s/<CERT_TWO>/${{ secrets.CERT_TWO }}/g;s/<RSA_PRIVATE>/${{ secrets.RSA_PRIVATE }}/g" $(dirname "$file")/kube_config | |
| fi | |
| ### | |
| ### Exclusive for Cloudflare Tunnel | |
| if [[ $file == tunnel/* ]]; then | |
| sed -i "s/<CLOUDFLARE>/${{ secrets.CLOUDFLARE }}/g;s/<ENV>/prod/g" $file | |
| fi | |
| ### | |
| /usr/bin/docker build $(dirname "$file") -t 10.10.10.100:32000/$(dirname $(dirname "$file")):prod | |
| echo "Pushing..." | |
| /usr/bin/docker push 10.10.10.100:32000/$(dirname $(dirname "$file")):prod | |
| fi | |
| done | |
| for file in ${{ steps.changed-files.outputs.all_changed_files }}; do | |
| if [[ $file == *.yaml && $file != .github/workflows/* ]]; then | |
| echo "Deploying: $file" | |
| /usr/local/bin/kubectl apply -f <(sed "s/\${ENV}/prod/g" $file) | |
| fi | |
| done |