check pipeline 026 #26
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: CI/CD Workflow | ||
on: | ||
push: | ||
branches: | ||
- master | ||
env: | ||
REPOSITORY_PATH: 'hutinskit' | ||
IMAGE_NAME: 'python-test-app' | ||
TAG: '1.0.138' | ||
ARGO_TEST_BRANCH: 'tino-test' | ||
ARGO_PROD_BRANCH: 'tino-prod' | ||
jobs: | ||
check-image: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v3 | ||
- | ||
name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- | ||
name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.HARBOR_CREDENTIALS_USR }} | ||
password: ${{ secrets.HARBOR_CREDENTIALS_PSW }} | ||
- | ||
name: Check Docker Image for ${{ env.IMAGE_NAME }} and push it if doesn't exists | ||
id: python-step | ||
run: | | ||
# Check if the image exists | ||
if docker pull ${{ env.REPOSITORY_PATH }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}; then | ||
echo "Python image already exists, skipping new build and push" | ||
else | ||
# Perform additional steps if the image does not exist | ||
echo "python_output=true" >> $GITHUB_OUTPUT | ||
fi | ||
outputs: | ||
python_output: ${{ steps.python-step.outputs.python_output }} | ||
result: ${{ job.status }} | ||
build_image: | ||
needs: check-image | ||
if: ${{ needs.check-image.outputs.python_output == 'true' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v3 | ||
- | ||
name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- | ||
name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.HARBOR_CREDENTIALS_USR }} | ||
password: ${{ secrets.HARBOR_CREDENTIALS_PSW }} | ||
- | ||
name: Build and push python | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: Dockerfile | ||
push: true | ||
#tags: ${{ steps.meta.outputs.tags }} | ||
tags: ${{ env.REPOSITORY_PATH }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} | ||
outputs: | ||
result: ${{ job.status }} | ||
deploy_k8s: | ||
runs-on: ubuntu-latest | ||
needs: [check-image, build_image] | ||
if: always() # set "always" | ||
strategy: | ||
matrix: | ||
deploy_env: ['test', 'prod'] | ||
steps: | ||
# run this action to get the workflow conclusion | ||
# You can get the conclusion via env (env.WORKFLOW_CONCLUSION) | ||
- uses: technote-space/workflow-conclusion-action@v3 | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v3 | ||
- | ||
name: Deploy to Kubernetes | ||
with: | ||
# status: ${{ env.WORKFLOW_CONCLUSION }} # neutral, success, skipped, cancelled, timed_out, action_required, failure | ||
status: skipped | ||
run: | | ||
Check failure on line 101 in .github/workflows/ci-cd.yaml
|
||
if [ "${{ matrix.deploy_env }}" == "test" ]; then | ||
branch="${{ env.ARGO_TEST_BRANCH }}" | ||
environment="test Kubernetes" | ||
elif [ "${{ matrix.deploy_env }}" == "prod" ]; then | ||
branch="${{ env.ARGO_PROD_BRANCH }}" | ||
environment="production Kubernetes" | ||
fi | ||
echo "Deploying to $environment..." | ||
git clone https://${{ secrets.ARGO_CREDENTIALS_USR }}:${{ secrets.ARGO_CREDENTIALS_PSW }}@github.com/${{ secrets.ARGO_CREDENTIALS_USR }}/argo-k8s-python.git | ||
git config --global user.name "tinhutins" | ||
git config --global user.email 'tino.hutinski@gmail.com' | ||
cd argo-k8s-python | ||
git checkout $branch | ||
cd k8s-apps-deployment/python-test/ | ||
kustomize edit set image ${{ env.REPOSITORY_PATH }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} | ||
git commit -am "Publish image ${{ env.IMAGE_NAME }}:${{ env.TAG }}" | ||
git push | ||
git_status=$(git status) | ||
if grep -q "nothing to commit, working tree clean" "$git_status"; then | ||
echo "Working tree is clean. No changes to commit." | ||
exit 0 |