|
| 1 | +--- |
| 2 | +name: Build |
| 3 | + |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - master |
| 9 | + schedule: |
| 10 | + - cron: "10 1 * * 0" |
| 11 | + |
| 12 | +env: |
| 13 | + ANSIBLE_FORCE_COLOR: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + # Test the images build and work correctly. |
| 17 | + test: |
| 18 | + name: Test |
| 19 | + runs-on: ubuntu-latest |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + solr_version: |
| 23 | + - '8.x' |
| 24 | + - '7.x' |
| 25 | + - '6.x' |
| 26 | + - '5.x' |
| 27 | + - '4.x' |
| 28 | + |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v2 |
| 31 | + |
| 32 | + - name: Set up Python 3. |
| 33 | + uses: actions/setup-python@v2 |
| 34 | + with: |
| 35 | + python-version: '3.x' |
| 36 | + |
| 37 | + - name: Install prerequisites. |
| 38 | + run: pip3 install ansible ansible-lint docker shyaml |
| 39 | + |
| 40 | + - name: Install role dependencies. |
| 41 | + run: ansible-galaxy install -r requirements.yml |
| 42 | + |
| 43 | + - name: Build the container. |
| 44 | + run: ansible-playbook --extra-vars="@vars/${{ matrix.solr_version }}.yml" main.yml |
| 45 | + |
| 46 | + - name: Get the exact version of Solr used. |
| 47 | + run: | |
| 48 | + echo "exact_version=$(cat vars/${{ matrix.solr_version }}.yml | shyaml get-value solr_version)" >> $GITHUB_ENV |
| 49 | +
|
| 50 | + - name: Run the container. |
| 51 | + run: docker run -d --name=solr -p 8983:8983 geerlingguy/solr:${{ env.exact_version }} |
| 52 | + |
| 53 | + - name: Verify solr is running. |
| 54 | + run: > |
| 55 | + docker exec solr ps -ax | grep -q "solr" |
| 56 | + && (echo 'solr is running: pass' && exit 0) |
| 57 | + || (echo 'solr is running: fail' && exit 1) |
| 58 | +
|
| 59 | + # If on master branch, build and release images. |
| 60 | + release: |
| 61 | + name: Release |
| 62 | + runs-on: ubuntu-latest |
| 63 | + needs: test |
| 64 | + if: github.ref == 'refs/heads/master' |
| 65 | + |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v2 |
| 68 | + |
| 69 | + - name: Set up Python 3. |
| 70 | + uses: actions/setup-python@v2 |
| 71 | + with: |
| 72 | + python-version: '3.x' |
| 73 | + |
| 74 | + - name: Install prerequisites. |
| 75 | + run: pip3 install ansible ansible-lint docker shyaml |
| 76 | + |
| 77 | + - name: Install role dependencies. |
| 78 | + run: ansible-galaxy install -r requirements.yml |
| 79 | + |
| 80 | + - name: Build the container. |
| 81 | + run: ansible-playbook --extra-vars="@vars/${{ matrix.solr_version }}.yml" main.yml |
| 82 | + |
| 83 | + - name: Get the exact version of Solr used. |
| 84 | + run: | |
| 85 | + echo "exact_version=$(cat vars/${{ matrix.solr_version }}.yml | shyaml get-value solr_version)" >> $GITHUB_ENV |
| 86 | +
|
| 87 | + - name: Login to DockerHub |
| 88 | + uses: docker/login-action@v1 |
| 89 | + with: |
| 90 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 91 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 92 | + |
| 93 | + - name: Build and push image. |
| 94 | + run: | |
| 95 | + # Push $solr_version tag. |
| 96 | + docker push geerlingguy/solr:${{ env.exact_version }} |
| 97 | +
|
| 98 | + # Push $solr_version tag. |
| 99 | + docker tag geerlingguy/solr:${{ env.exact_version }} geerlingguy/solr:${{ matrix.solr_version }} |
| 100 | + docker push geerlingguy/solr:${{ matrix.solr_version }} |
| 101 | +
|
| 102 | + # Push latest tag if building latest version. |
| 103 | + if [[ "${{ matrix.solr_version }}" == "8.x" ]]; then |
| 104 | + docker tag geerlingguy/solr:${{ env.exact_version }} geerlingguy/solr:latest |
| 105 | + docker push geerlingguy/solr:latest |
| 106 | + fi |
0 commit comments