-
Notifications
You must be signed in to change notification settings - Fork 8
177 lines (157 loc) · 6.5 KB
/
part_build.yml
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
on:
workflow_call:
inputs:
releaseHexPmOS:
required: false
type: string
default: debian
releaseHexPmOSVersion:
required: false
type: string
default: bullseye-20230227-slim
dockerTag:
required: false
type: string
dockerBuild:
required: false
type: boolean
default: true
name: "Build"
jobs:
detect_clean_versions:
name: Detect Clean Versions
runs-on: ubuntu-latest
outputs:
elixirVersion: "${{ env.ELIXIR_VERSION }}"
otpVersion: "${{ env.OTP_VERSION }}"
steps:
- uses: actions/checkout@v3
- name: "Read .tool-versions"
id: toolVersions
run: |
ELIXIR_VERSION="$(cat .tool-versions | grep elixir | cut -d' ' -f2- | sed 's/-otp-[0-9]*//')"
echo Elixir: $ELIXIR_VERSION
echo "ELIXIR_VERSION=${ELIXIR_VERSION}" >> $GITHUB_ENV
OTP_VERSION="$(cat .tool-versions | grep erlang | cut -d' ' -f2-)"
echo OTP: $OTP_VERSION
echo "OTP_VERSION=${OTP_VERSION}" >> $GITHUB_ENV
compile_assets:
name: Compile Assets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: erlef/setup-elixir@v1
id: setupBEAM
with:
version-file: '.tool-versions'
version-type: strict
- uses: actions/cache@v3
with:
path: deps
key: deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ steps.setupBEAM.outputs.elixir-version }}-${{ hashFiles('mix.lock') }}
restore-keys: |
deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ steps.setupBEAM.outputs.elixir-version }}-
- run: mix deps.get
- uses: actions/setup-node@v3
id: setupNode
with:
node-version-file: '.tool-versions'
- run: npm config set cache $GITHUB_WORKSPACE/.ci-npm-cache
- uses: actions/cache@v3
with:
path: .ci-npm-cache
key: deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ steps.setupBEAM.outputs.elixir-version }}-${{ hashFiles('assets/package-lock.json') }}
restore-keys: |
deps-${{ runner.os }}-${{ steps.setupNode.outputs.node-version }}-
- run: npm ci --prefix=assets
- run: npm run deploy --prefix=assets
- uses: actions/upload-artifact@v3
with:
name: compile_assets
path: priv/static
mix_release:
name: "Mix Release"
runs-on: ubuntu-latest
needs: ['detect_clean_versions', 'compile_assets']
container:
image: hexpm/elixir:${{ needs.detect_clean_versions.outputs.elixirVersion }}-erlang-${{ needs.detect_clean_versions.outputs.otpVersion }}-${{ inputs.releaseHexPmOS }}-${{ inputs.releaseHexPmOSVersion }}
env:
MIX_ENV: prod
steps:
- uses: actions/checkout@v3
- run: |
apt-get update -yqq
apt-get install -yqq git
mix local.hex --force
mix local.rebar --force
- uses: actions/cache@v3
with:
path: deps
key: deps-docker-${{ env.MIX_ENV }}-${{ runner.os }}-${{ needs.detect_clean_versions.outputs.otpVersion }}-${{ needs.detect_clean_versions.outputs.elixirVersion }}-${{ hashFiles('mix.lock') }}
restore-keys: |
deps-docker-${{ env.MIX_ENV }}-${{ runner.os }}-${{ needs.detect_clean_versions.outputs.otpVersion }}-${{ needs.detect_clean_versions.outputs.elixirVersion }}-
- run: mix deps.get
- uses: actions/cache@v3
with:
path: |
_build/prod
!_build/prod/rel
key: compile-docker-${{ env.MIX_ENV }}-${{ runner.os }}-${{ needs.detect_clean_versions.outputs.otpVersion }}-${{ needs.detect_clean_versions.outputs.elixirVersion }}-${{ hashFiles('mix.lock') }}
restore-keys: |
compile-docker-${{ env.MIX_ENV }}-${{ runner.os }}-${{ needs.detect_clean_versions.outputs.otpVersion }}-${{ needs.detect_clean_versions.outputs.elixirVersion }}-
- run: mix deps.compile
env:
MIX_ENV: prod
- run: mix compile --warning-as-errors
env:
MIX_ENV: prod
- uses: actions/download-artifact@v3
with:
name: compile_assets
path: priv/static
- run: mix phx.digest
- run: mix release --overwrite
- run: tar -czvf release.tar.gz _build/prod/rel/hygeia
- uses: actions/upload-artifact@v3
with:
name: mix_release
path: release.tar.gz
docker_build:
name: "Docker Build"
runs-on: ubuntu-latest
needs: ['detect_clean_versions', 'mix_release']
if: ${{ inputs.dockerBuild }}
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: mix_release
path: .
- run: tar -zxvf release.tar.gz
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: satackey/[email protected]
# Ignore the failure of a step and avoid terminating the job.
continue-on-error: true
with:
key: docker-${{ runner.os }}-${{ needs.detect_clean_versions.outputs.elixirVersion }}-erlang-${{ needs.detect_clean_versions.outputs.otpVersion }}-${{ inputs.releaseHexPmOS }}-${{ inputs.releaseHexPmOSVersion }}-${{ hashFiles('Dockerfile') }}
restore-keys: |
ocker-${{ runner.os }}-${{ needs.detect_clean_versions.outputs.elixirVersion }}-erlang-${{ needs.detect_clean_versions.outputs.otpVersion }}-${{ inputs.releaseHexPmOS }}-${{ inputs.releaseHexPmOSVersion }}-
- run: |
docker \
build \
--tag ghcr.io/${{ github.repository }}:$GITHUB_SHA \
--build-arg ELIXIR_VERSION="${{ needs.detect_clean_versions.outputs.elixirVersion }}" \
--build-arg ERLANG_VERSION="${{ needs.detect_clean_versions.outputs.otpVersion }}" \
--build-arg HEXPM_BOB_OS="${{ inputs.releaseHexPmOS }}" \
--build-arg HEXPM_BOB_OS_VERSION="${{ inputs.releaseHexPmOSVersion }}" \
.
- run: docker push ghcr.io/${{ github.repository }}:$GITHUB_SHA
- run: docker tag ghcr.io/${{ github.repository }}:$GITHUB_SHA ghcr.io/${{ github.repository }}:${{ inputs.dockerTag }}
if: ${{ inputs.dockerTag }}
- run: docker push ghcr.io/${{ github.repository }}:${{ inputs.dockerTag }}
if: ${{ inputs.dockerTag }}