Only write secret file if it does not exist or is empty #143
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: CI/CD Workflow | |
| on: | |
| push: | |
| branches: | |
| - master | |
| env: | |
| CERTS_DIR: certs | |
| CERTS_EXPIRY: 730 | |
| CI_USER_PASSWORD: cI_User@123 | |
| JENKINS_WORKDIR: ./docker/jenkins | |
| REGISTRY_CONTAINER_NAME: registry | |
| DOCKER_COMPOSE_FILE: docker-compose.yml | |
| DOCKER_VERSION: 5:28.0.1-1~ubuntu.24.04~noble | |
| jobs: | |
| build: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Docker with specific version | |
| run: sh ./install_docker.sh | |
| working-directory: ./.github/workflows/scripts | |
| - name: Check if docker compose is available before proceeding | |
| run: docker compose version || { echo "docker compose is not installed or not in PATH"; exit 1; } | |
| - name: Generate certificate for the registry service | |
| run: | | |
| mkdir -p ${{ env.CERTS_DIR }} | |
| openssl req \ | |
| -newkey rsa:4096 -nodes -sha256 -keyout ${{ env.CERTS_DIR }}/registry.key \ | |
| -x509 -days ${{ env.CERTS_EXPIRY }} -out ${{ env.CERTS_DIR }}/registry.crt \ | |
| -subj "/CN=${{ env.REGISTRY_CONTAINER_NAME }}" \ | |
| -addext "subjectAltName=DNS:${{ env.REGISTRY_CONTAINER_NAME }}" | |
| working-directory: ${{ env.JENKINS_WORKDIR }} | |
| - name: Create secrets files | |
| id: create_secrets | |
| run: | | |
| export JENKINS_CI_USER_PASSWORD=${{ env.CI_USER_PASSWORD }} | |
| sh ./scripts/bootstrap.sh | |
| working-directory: ${{ env.JENKINS_WORKDIR }} | |
| - name: Start and setup the container | |
| id: docker_start | |
| run: | | |
| docker compose up -d | |
| working-directory: ${{ env.JENKINS_WORKDIR }} | |
| - name: Test Jenkins server is up and running | |
| id: test_jenkins | |
| run: sh tests/test_jenkins.sh | |
| working-directory: ${{ env.JENKINS_WORKDIR }} | |
| - name: Test the ownership of dirs | |
| if: steps.docker_start.outcome == 'success' | |
| run: docker exec jenkins sh /usr/local/bin/tests/test_ownership.sh | |
| working-directory: ${{ env.JENKINS_WORKDIR }} | |
| - name: Generate the API token for the CI_User needed to be used with test scripts | |
| if: steps.test_jenkins.outcome == 'success' | |
| id: generate_token | |
| run: docker exec jenkins sh /usr/local/bin/scripts/generate_token.sh | |
| working-directory: ${{ env.JENKINS_WORKDIR }} | |
| - name: Test Jenkins agents are online and connected | |
| if: steps.generate_token.outcome == 'success' | |
| run: docker exec jenkins sh /usr/local/bin/tests/test_agents.sh | |
| working-directory: ${{ env.JENKINS_WORKDIR }} | |
| - name: Run the sanity check pipeline | |
| if: steps.generate_token.outcome == 'success' | |
| run: docker exec jenkins sh /usr/local/bin/tests/test_jobs.sh | |
| working-directory: ${{ env.JENKINS_WORKDIR }} | |
| - name: Debug Running Containers | |
| if: ${{ always() }} | |
| run: docker ps -a | |
| - name: Collect Docker container logs | |
| if: ${{ always() }} | |
| run: | | |
| for container in $(docker ps -a --format '{{.Names}}'); do | |
| echo "---- Logs for $container ----" | |
| docker logs "$container" | sed "s/^/[$container] /" | |
| echo "---- End of logs for $container ----" | |
| done | |
| - name: Clean up Docker containers and volumes | |
| if: ${{ always() }} | |
| run: | | |
| [ -f "${{ env.DOCKER_COMPOSE_FILE }}" ] || { echo "Compose file not found!"; exit 1; } | |
| if docker compose ps -q | grep -q .; then | |
| docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} down --volumes --remove-orphans | |
| else | |
| echo "No containers to clean up." | |
| fi | |
| working-directory: ${{ env.JENKINS_WORKDIR }} |