|
| 1 | +--- |
| 2 | +name: Build |
| 3 | + |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - master |
| 9 | + schedule: |
| 10 | + - cron: "45 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 | + php_version: |
| 23 | + - '7.4' |
| 24 | + - '7.3' |
| 25 | + - '7.2' |
| 26 | + - '7.1' |
| 27 | + |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v2 |
| 30 | + |
| 31 | + - name: Set up Python 3. |
| 32 | + uses: actions/setup-python@v2 |
| 33 | + with: |
| 34 | + python-version: '3.x' |
| 35 | + |
| 36 | + - name: Install prerequisites. |
| 37 | + run: pip3 install ansible docker |
| 38 | + |
| 39 | + - name: Install role dependencies. |
| 40 | + run: ansible-galaxy install -r requirements.yml |
| 41 | + |
| 42 | + - name: Build the container. |
| 43 | + run: ansible-playbook --extra-vars="@vars/${{ matrix.php_version }}.yml" main.yml |
| 44 | + |
| 45 | + - name: Run the container. |
| 46 | + run: docker run -d --name=php-apache -p 8080:80 geerlingguy/php-apache:${{ matrix.php_version }} /usr/sbin/apache2ctl -D FOREGROUND |
| 47 | + |
| 48 | + - name: Verify container has correct PHP version and works. |
| 49 | + run: | |
| 50 | + docker exec php-apache php -v | grep ${{ matrix.php_version }} |
| 51 | + curl http://localhost:8080/ |
| 52 | +
|
| 53 | + # If on master branch, build and release images. |
| 54 | + release: |
| 55 | + name: Release |
| 56 | + runs-on: ubuntu-latest |
| 57 | + strategy: |
| 58 | + matrix: |
| 59 | + php_version: |
| 60 | + - '7.4' |
| 61 | + - '7.3' |
| 62 | + - '7.2' |
| 63 | + - '7.1' |
| 64 | + needs: test |
| 65 | + if: github.ref == 'refs/heads/master' |
| 66 | + |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v2 |
| 69 | + |
| 70 | + - name: Set up Python 3. |
| 71 | + uses: actions/setup-python@v2 |
| 72 | + with: |
| 73 | + python-version: '3.x' |
| 74 | + |
| 75 | + - name: Install prerequisites. |
| 76 | + run: pip3 install ansible docker |
| 77 | + |
| 78 | + - name: Install role dependencies. |
| 79 | + run: ansible-galaxy install -r requirements.yml |
| 80 | + |
| 81 | + - name: Build the container. |
| 82 | + run: ansible-playbook --extra-vars="@vars/${{ matrix.php_version }}.yml" main.yml |
| 83 | + |
| 84 | + - name: Login to DockerHub |
| 85 | + uses: docker/login-action@v1 |
| 86 | + with: |
| 87 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 88 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 89 | + |
| 90 | + - name: Push image. |
| 91 | + run: | |
| 92 | + # Push $solr_version tag. |
| 93 | + docker push geerlingguy/php-apache:${{ matrix.php_version }} |
| 94 | +
|
| 95 | + # Push $php_version + '.x' tag. |
| 96 | + docker tag geerlingguy/php-apache:${{ matrix.php_version }} geerlingguy/php-apache:${{ matrix.php_version }}.x |
| 97 | + docker push geerlingguy/php-apache:${{ matrix.php_version }}.x |
| 98 | +
|
| 99 | + # Push $php_version + '.PHP_RELEASE_VERSION' tag. |
| 100 | + php_release_version=$(docker run --rm geerlingguy/php-apache:${{ matrix.php_version }} bash -c "php -r 'echo PHP_RELEASE_VERSION;'") |
| 101 | + docker tag geerlingguy/php-apache:${{ matrix.php_version }} geerlingguy/php-apache:${{ matrix.php_version }}.${php_release_version} |
| 102 | + docker push geerlingguy/php-apache:${{ matrix.php_version }}.${php_release_version} |
| 103 | +
|
| 104 | + # Push latest tag if building latest version. |
| 105 | + if [[ "${{ matrix.php_version }}" == "7.4" ]]; then |
| 106 | + docker tag geerlingguy/php-apache:${{ matrix.php_version }} geerlingguy/php-apache:latest |
| 107 | + docker push geerlingguy/php-apache:latest |
| 108 | + fi |
0 commit comments