|
1 | 1 | name: ci |
2 | 2 |
|
3 | 3 | on: |
4 | | - schedule: |
5 | | - - cron: "0 0 1 * *" |
6 | 4 | push: |
7 | | - branches: |
8 | | - - "**" |
9 | | - tags: |
10 | | - - "v*.*.*" |
| 5 | + branches: [ "dev", "main" ] |
11 | 6 | pull_request: |
12 | | - branches: |
13 | | - - "main" |
| 7 | + branches: [ "dev", "main" ] |
14 | 8 |
|
15 | 9 | env: |
16 | | - docker_user: ${{ secrets.DOCKERHUB_USERNAME }} |
17 | | - app_name: ${{ vars.APP_NAME }} |
| 10 | + # Use docker.io for Docker Hub if empty |
| 11 | + REGISTRY: docker.io |
| 12 | + # github.repository as <account>/<repo> |
| 13 | + IMAGE_NAME: ${{ github.repository }} |
18 | 14 |
|
19 | 15 | jobs: |
20 | | - docker: |
21 | | - strategy: |
22 | | - fail-fast: true |
| 16 | + build: |
23 | 17 | runs-on: ubuntu-latest |
24 | 18 | steps: |
25 | | - - name: Checkout |
| 19 | + - uses: actions/checkout@v3 |
| 20 | + - name: Build the Docker image |
| 21 | + run: docker-compose build --no-cache --force-rm |
| 22 | + |
| 23 | + test: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v2 |
| 27 | + - name: Test the Docker image |
| 28 | + run: docker-compose up -d |
| 29 | + |
| 30 | + push_to_registry: |
| 31 | + name: Push Docker image to Docker Hub |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - name: Check out the repo |
26 | 35 | uses: actions/checkout@v3 |
27 | | - - name: Docker meta |
28 | | - id: meta |
29 | | - uses: docker/metadata-action@v4 |
30 | | - with: |
31 | | - # list of Docker images to use as base name for tags |
32 | | - images: | |
33 | | - ${{ env.docker_user }}/${{ env.app_name }} |
34 | | - # generate Docker tags based on the following events/attributes |
35 | | - tags: | |
36 | | - type=schedule |
37 | | - type=ref,event=branch |
38 | | - type=ref,event=pr |
39 | | - type=semver,pattern={{version}} |
40 | | - type=semver,pattern={{major}}.{{minor}} |
41 | | - type=semver,pattern={{major}} |
42 | | - type=sha |
43 | | -
|
44 | | - - name: Set up QEMU |
45 | | - uses: docker/setup-qemu-action@v3 |
46 | 36 |
|
47 | 37 | - name: Set up Docker Buildx |
48 | | - uses: docker/setup-buildx-action@v3 |
| 38 | + uses: docker/setup-buildx-action@v2 |
49 | 39 |
|
50 | | - - name: Login to Docker Hub |
51 | | - if: github.event_name != 'pull_request' |
52 | | - uses: docker/login-action@v2 |
| 40 | + - name: Log in to Docker Hub |
| 41 | + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 |
53 | 42 | with: |
54 | 43 | username: ${{ secrets.DOCKERHUB_USERNAME }} |
55 | 44 | password: ${{ secrets.DOCKERHUB_TOKEN }} |
56 | 45 |
|
57 | | - - name: Build and push |
58 | | - uses: docker/build-push-action@v5 |
| 46 | + - name: Extract metadata (tags, labels) for Docker |
| 47 | + id: meta |
| 48 | + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 |
| 49 | + with: |
| 50 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 51 | + |
| 52 | + - name: Build and push Docker image |
| 53 | + uses: docker/build-push-action@v2 |
59 | 54 | with: |
60 | | - context: . |
61 | | - push: ${{ github.event_name != 'pull_request' }} |
| 55 | + context: "{{defaultContext}}" |
| 56 | + push: true |
62 | 57 | tags: ${{ steps.meta.outputs.tags }} |
63 | 58 | labels: ${{ steps.meta.outputs.labels }} |
0 commit comments