|
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - master |
| 7 | + tags: |
| 8 | + - v* |
7 | 9 | pull_request: |
8 | 10 |
|
9 | 11 | jobs: |
10 | | - test: |
| 12 | + image: |
11 | 13 | runs-on: ubuntu-latest |
12 | 14 | env: |
13 | | - DOCKER_TAG: ${{ github.sha }} |
| 15 | + DOCKERHUB_USERNAME: levonet |
14 | 16 | steps: |
| 17 | + |
15 | 18 | - name: Checkout |
16 | 19 | uses: actions/checkout@v2 |
17 | | - - name: Build the Docker image |
18 | | - run: docker build -t levonet/nginx:${DOCKER_TAG} . |
| 20 | + |
| 21 | + - name: Docker meta |
| 22 | + id: meta |
| 23 | + uses: docker/metadata-action@v3 |
| 24 | + with: |
| 25 | + images: levonet/nginx |
| 26 | + tags: | |
| 27 | + type=ref,event=branch |
| 28 | + type=ref,event=pr |
| 29 | + type=semver,pattern={{version}} |
| 30 | + type=semver,pattern={{major}}.{{minor}} |
| 31 | + flavor: | |
| 32 | + latest=auto |
| 33 | + suffix=-alpine,onlatest=false |
| 34 | +
|
| 35 | + - name: Login to DockerHub |
| 36 | + if: ${{ github.event_name != 'pull_request' }} |
| 37 | + uses: docker/login-action@v1 |
| 38 | + with: |
| 39 | + username: ${{ env.DOCKERHUB_USERNAME }} |
| 40 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 41 | + |
| 42 | + - name: Build and export to Docker |
| 43 | + uses: docker/build-push-action@v2 |
| 44 | + with: |
| 45 | + context: . |
| 46 | + load: true |
| 47 | + tags: ${{ fromJSON(steps.meta.outputs.json).tags[0] }} |
| 48 | + |
19 | 49 | - name: Run test |
| 50 | + env: |
| 51 | + DOCKER_IMAGE: ${{ fromJSON(steps.meta.outputs.json).tags[0] }} |
20 | 52 | run: | |
21 | 53 | cd test |
22 | | - make |
| 54 | + make test |
| 55 | +
|
| 56 | + - name: Build and push |
| 57 | + if: ${{ github.event_name != 'pull_request' }} |
| 58 | + uses: docker/build-push-action@v2 |
| 59 | + with: |
| 60 | + context: . |
| 61 | + push: true |
| 62 | + tags: ${{ steps.meta.outputs.tags }} |
| 63 | + labels: ${{ steps.meta.outputs.labels }} |
| 64 | + |
| 65 | + - name: Docker Hub Description |
| 66 | + if: ${{ github.event_name != 'pull_request' }} |
| 67 | + uses: peter-evans/dockerhub-description@v2 |
| 68 | + with: |
| 69 | + username: ${{ env.DOCKERHUB_USERNAME }} |
| 70 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 71 | + repository: levonet/nginx |
0 commit comments