summaryrefslogtreecommitdiff
path: root/.github/workflows/docker_build.yml
blob: 7bbb7d606badf434b1074453a837e66a25167dbc (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: docker-build
on:
  push:
    branches:
      - 'master'
  pull_request:
    types: ['labeled', 'opened', 'synchronize', 'reopened']

concurrency:
  group: ${{ github.head_ref }} || concat(${{ github.ref }}, ${{ github.workflow }})
  cancel-in-progress: true

jobs:
  docker-build-n-deploy-dev:
    strategy:
      fail-fast: true
      matrix:
        os: [ubuntu-20.04]
    runs-on: ${{ matrix.os }}
    if: |
      github.repository == 'azerothcore/azerothcore-wotlk'
      && !github.event.pull_request.draft
      && (github.ref == 'refs/heads/master' || contains(github.event.pull_request.labels.*.name, 'run-build') || github.event.label.name == 'run-build')
    env:
      COMPOSE_DOCKER_CLI_BUILD: 1
      DOCKER_BUILDKIT: 1

    steps:
      - name: Extract branch name
        shell: bash
        run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
        id: extract_branch

      - name: Maximize build space
        uses: easimon/maximize-build-space@master
        with:
          root-reserve-mb: 10240
          swap-size-mb: 1024
          remove-dotnet: 'true'
          remove-android: 'true'
          remove-haskell: 'true'

      - name: Configure
        run: |
          sudo rm -rf "$AGENT_TOOLSDIRECTORY"
          docker --version
          docker compose version

      - uses: actions/checkout@v3
        with:
          fetch-depth: 2

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

      - name: Login to Docker Hub
        if: github.repository == 'azerothcore/azerothcore-wotlk' && steps.extract_branch.outputs.branch == 'master'
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build Dev
        if: github.repository == 'azerothcore/azerothcore-wotlk'
        env:
          #DOCKER_IMAGE_TAG: ${{ steps.extract_branch.outputs.branch }}
          DOCKER_CLIENT_TIMEOUT: 400
          COMPOSE_HTTP_TIMEOUT: 400
        run: |
          export CACHEBUST=$EPOCHSECONDS
          export DOCKER_USER_ID=$(id -u)
          export DOCKER_GROUP_ID=$(id -u)
          # pull the images first to load the docker cache layers
          #./acore.sh docker pull
          ./acore.sh docker build
          output=$(./acore.sh version | grep "AzerothCore Rev. ") && version=${output#"AzerothCore Rev. "}
          DOCKER_IMAGE_TAG=$version docker compose --profile dev --profile local build

      - name: Deploy Dev
        #env:
        #  DOCKER_IMAGE_TAG: ${{ steps.extract_branch.outputs.branch }}
        if: github.repository == 'azerothcore/azerothcore-wotlk' && steps.extract_branch.outputs.branch == 'master'
        run: |
          docker compose --profile dev --profile local push
          output=$(./acore.sh version | grep "AzerothCore Rev. ") && version=${output#"AzerothCore Rev. "}
          DOCKER_IMAGE_TAG=$version docker compose --profile dev --profile local push

  docker-build-n-deploy-prod:
    strategy:
      fail-fast: true
      matrix:
        os: [ubuntu-20.04]
    runs-on: ${{ matrix.os }}
    if: |
      github.repository == 'azerothcore/azerothcore-wotlk'
      && !github.event.pull_request.draft
      && (github.ref == 'refs/heads/master' || contains(github.event.pull_request.labels.*.name, 'run-build') || github.event.label.name == 'run-build')
    env:
      COMPOSE_DOCKER_CLI_BUILD: 1
      DOCKER_BUILDKIT: 1

    steps:
      - name: Extract branch name
        shell: bash
        run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
        id: extract_branch

      - name: Maximize build space
        uses: easimon/maximize-build-space@master
        with:
          root-reserve-mb: 10240
          swap-size-mb: 1024
          remove-dotnet: 'true'
          remove-android: 'true'
          remove-haskell: 'true'

      - name: Configure
        run: |
          sudo rm -rf "$AGENT_TOOLSDIRECTORY"
          docker --version
          docker compose version

      - uses: actions/checkout@v3
        with:
          fetch-depth: 2

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

      - name: Login to Docker Hub
        if: github.repository == 'azerothcore/azerothcore-wotlk' && steps.extract_branch.outputs.branch == 'master'
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Cache
        uses: actions/cache@v2
        with:
          path: var/docker/ccache
          key: ccache:${{ matrix.os }}:clang:without-modules:${{ github.ref }}:${{ github.sha }}
          restore-keys: |
            ccache:${{ matrix.os }}:clang:without-modules:${{ github.ref }}
            ccache:${{ matrix.os }}:clang:without-modules

      - name: Build Production images
        if: github.repository == 'azerothcore/azerothcore-wotlk'
        env:
          #DOCKER_IMAGE_TAG: ${{ steps.extract_branch.outputs.branch }}
          DOCKER_CLIENT_TIMEOUT: 220
          COMPOSE_HTTP_TIMEOUT: 220
        run: |
          export DOCKER_USER_ID=$(id -u)
          export DOCKER_GROUP_ID=$(id -u)
          # pull the images first to load the docker cache layers
          #./acore.sh docker prod:pull
          ./acore.sh docker prod:build
          output=$(./acore.sh version | grep "AzerothCore Rev. ") && version=${output#"AzerothCore Rev. "}
          DOCKER_IMAGE_TAG=$version ./acore.sh docker prod:build
          # create the container to allow the copy right after
          docker compose create ac-build-prod
          docker compose cp ac-build-prod:/azerothcore/var/ccache var/docker/
          echo "ccache exported"

      - name: Deploy Production images
        #env:
        #  DOCKER_IMAGE_TAG: ${{ steps.extract_branch.outputs.branch }}
        if: github.repository == 'azerothcore/azerothcore-wotlk' && steps.extract_branch.outputs.branch == 'master'
        run: |
          docker compose --profile prod push
          output=$(./acore.sh version | grep "AzerothCore Rev. ") && version=${output#"AzerothCore Rev. "}
          DOCKER_IMAGE_TAG=$version docker compose --profile prod push


  dispatch-acore-docker:
    needs: [ docker-build-n-deploy-prod , docker-build-n-deploy-dev]
    runs-on: ubuntu-latest
    steps:
      - name: Extract branch name
        shell: bash
        run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
        id: extract_branch

      - name: Repository Dispatch
        if: github.repository == 'azerothcore/azerothcore-wotlk' && steps.extract_branch.outputs.branch == 'master'
        uses: peter-evans/repository-dispatch@v2
        with:
          token: ${{ secrets.ACORE_DOCKER_REPO_ACCESS_TOKEN }}
          repository: azerothcore/acore-docker
          event-type: azerothcore-new-images
          client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'