summaryrefslogtreecommitdiff
path: root/.github/workflows/oci.yaml
blob: fb86c08c7acb28ace1cc8c2e1ddb454333c081ec (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# https://github.com/marketplace/actions/build-and-push-docker-images
name: OCI
on:
  push:
    paths:
      - 'deps/**'
      - 'packaging/**'
      - 'scripts/**'
      - Makefile
      - plugins.mk
      - rabbitmq-components.mk
      - .github/workflows/oci.yaml
env:
  GENERIC_UNIX_ARCHIVE: ${{ github.workspace }}/PACKAGES/rabbitmq-server-generic-unix-${{ github.sha }}.tar.xz
  RABBITMQ_VERSION: ${{ github.sha }}
  VERSION: ${{ github.sha }}
jobs:

  # This job will build one docker image per supported Erlang major version.
  # Each image will have two tags (one containing the Git commit SHA, one containing the branch name).
  #
  # For example, for Git commit SHA '111aaa' and branch name 'main' and maximum supported Erlang major version '24',
  # the following tags will be pushed to Dockerhub:
  #
  # * 111aaa-otp-min (image OTP 23)
  # * main-otp-min (image OTP 23)
  # * 111aaa-otp-max (image OTP 24)
  # * main-otp-max (image OTP 24)

  build-publish-dev:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
          # Build image for every supported Erlang major version.
          # Source of truth for OTP versions (min & max): https://www.rabbitmq.com/which-erlang.html
          image_tag_suffix:
            - otp-min
            - otp-max
    steps:
      - name: Checkout
        uses: actions/checkout@v2.3.5

      - name: Load version info
        id: load-info
        run: |
          FILE=packaging/docker-image/otp-versions/${{ matrix.image_tag_suffix }}.yaml
          echo "::set-output name=otp::$(yq eval '.otp' $FILE)"
          echo "::set-output name=otp_sha256::$(yq eval '.otp_sha256' $FILE)"
          echo "::set-output name=elixir::$(yq eval '.elixir' $FILE)"

      - name: Set up Erlang & Elixir
        uses: erlef/setup-beam@v1.9
        with:
          otp-version: ${{ steps.load-info.outputs.otp }}
          elixir-version: ${{ steps.load-info.outputs.elixir }}

      - name: Build generic unix package
        run: |
          make package-generic-unix PROJECT_VERSION=${{ github.sha }}

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Cache Docker layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-${{ matrix.image_tag_suffix }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-${{ matrix.image_tag_suffix }}-buildx-

      - name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}

      - name: Expand generic-unix-package
        working-directory: packaging/docker-image
        run: |
          xzcat ${GENERIC_UNIX_ARCHIVE} | tar xvf -

      - name: Compute image tags
        id: compute-tags
        run: |
          echo "::set-output name=TAG_1::${{ github.sha }}-${{ matrix.image_tag_suffix }}"
          echo "::set-output name=TAG_2::${GITHUB_REF##*/}-${{ matrix.image_tag_suffix }}"

      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: packaging/docker-image
          push: true
          tags: |
            pivotalrabbitmq/rabbitmq:${{ steps.compute-tags.outputs.TAG_1 }}
            pivotalrabbitmq/rabbitmq:${{ steps.compute-tags.outputs.TAG_2 }}
          build-args: |
            SKIP_PGP_VERIFY=true
            PGP_KEYSERVER=pgpkeys.eu
            OTP_VERSION=${{ steps.load-info.outputs.otp }}
            OTP_SHA256=${{ steps.load-info.outputs.otp_sha256 }}
            RABBITMQ_BUILD=rabbitmq_server-${{ github.sha }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache-new

      # Temp fix
      # https://github.com/docker/build-push-action/issues/252
      # https://github.com/moby/buildkit/issues/1896
      - name: Move cache
        run: |
          rm -rf /tmp/.buildx-cache
          mv /tmp/.buildx-cache-new /tmp/.buildx-cache