summaryrefslogtreecommitdiff
path: root/.github/workflows/docker.yml
blob: 622ad94bd1ab7345f66ed1602048ecb263937fb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: Docker

on:
  push:
    branches: [ master ]
    tags: [ '*' ]
  workflow_dispatch:


permissions:
  contents: read # to fetch code (actions/checkout)

jobs:
  push:
    if: github.repository == 'rq/rq'
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Push
        run: |
          # Parse Version
          # "master" -> "master"
          # "v1.2.3" -> "1.2.3", "1.2", "1", "latest"

          VERSIONS=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')

          [[ "${{ github.ref }}" == "refs/tags/"* ]] && {
            VERSIONS=$(echo $VERSIONS | sed -e 's/^v//')
            i="$VERSIONS"
            while [[ "$i" == *"."* ]]
              do i="$(echo "$i" | sed 's/\(.*\)\..*/\1/g')"
                 VERSIONS="$VERSIONS $i"
            done
            VERSIONS="$VERSIONS latest"
          }
          
          echo Building with tags: $VERSIONS

          # Login to registries
          echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
          echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u selwin --password-stdin

          # Build image
          docker build . --tag worker

          # Tag and Push
          for VERSION in $VERSIONS
            do docker tag worker redisqueue/worker:$VERSION
               docker push redisqueue/worker:$VERSION
               docker tag worker docker.pkg.github.com/rq/rq/worker:$VERSION
               docker push docker.pkg.github.com/rq/rq/worker:$VERSION
          done