diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59fccb0..d26cbf4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,10 @@ jobs: id: get_repo_url run: echo "repo_url=${{ github.server_url }}/${{ github.repository }}" >> $GITHUB_OUTPUT + - name: Check if repository is private + id: check_private + run: echo "is_private=${{ github.event.repository.private }}" >> $GITHUB_ENV + - name: Log in to Docker Hub uses: docker/login-action@v2 with: @@ -36,10 +40,17 @@ jobs: - name: Run container with branch and repo info run: | - docker run -e BRANCH_NAME=${{ steps.extract_branch.outputs.branch }} \ - -e REPO_URL=${{ steps.get_repo_url.outputs.repo_url }} \ - ${{ secrets.DOCKER_IMAGE }} || exit 1 + if [ "${{ env.is_private }}" = "true" ]; then + docker run -e BRANCH_NAME=${{ steps.extract_branch.outputs.branch }} \ + -e REPO_URL=${{ steps.get_repo_url.outputs.repo_url }} \ + -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} \ + ${{ secrets.DOCKER_IMAGE }} || exit 1 + else + docker run -e BRANCH_NAME=${{ steps.extract_branch.outputs.branch }} \ + -e REPO_URL=${{ steps.get_repo_url.outputs.repo_url }} \ + ${{ secrets.DOCKER_IMAGE }} || exit 1 + fi - name: Verify container exit status - run: | - echo "Container ran successfully." + run: echo "Container ran successfully." + diff --git a/init.sh b/init.sh index 0f9e257..fe8ebf7 100644 --- a/init.sh +++ b/init.sh @@ -2,8 +2,14 @@ PIPELINE_REPO_PATH="/root/wazuh_pipeline" # Setup pipeline repo -git clone "$REPO_URL" "$PIPELINE_REPO_PATH" -cd "$PIPELINE_REPO_PATH" || 1 +if [ -n "$GITHUB_TOKEN" ]; then + REPO_URL_WITH_TOKEN="https://${GITHUB_TOKEN}@${REPO_URL#https://}" + git clone "$REPO_URL_WITH_TOKEN" "$PIPELINE_REPO_PATH" +else + git clone "$REPO_URL" "$PIPELINE_REPO_PATH" +fi + +cd "$PIPELINE_REPO_PATH" || exit 1 chmod +x ./*.sh # Check for the -i flag @@ -11,4 +17,4 @@ if [ "$1" = "-i" ]; then ./main.sh -i else ./main.sh -fi \ No newline at end of file +fi