-
Notifications
You must be signed in to change notification settings - Fork 2
104 lines (97 loc) · 3.84 KB
/
docker.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
name: Build docker image for subsequent jobs, resuing where possible.
on:
workflow_call:
inputs:
dockerfile:
description: 'Path to the dockerfile to be built'
required: true
type: string
image_name:
description: 'Name to give to the built docker image'
required: true
type: string
outputs:
image:
value: ${{ jobs.build_docker.outputs.image }}
jobs:
build_docker:
name: Build docker image
runs-on: ubuntu-latest
outputs:
image: ${{ steps.container_tag.outputs.tag }}
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to registry
uses: docker/login-action@v2
with:
registry: ${{ vars.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Clear more space
# See https://github.com/actions/runner-images/issues/2840
# - otherwise the runner runs out of space when building the tezos image
shell: bash
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo df -h
- name: Checkout
uses: actions/checkout@v3
- name: Branches ref
id: branches
shell: bash
run: |
echo "source=$(echo ${{ github.head_ref }} | cut -c -63 | sed -E 's/[^a-z0-9-]+/-/g' | sed -E 's/^-*([a-z0-9-]+[a-z0-9])-*$$/\1/g')" >> $GITHUB_OUTPUT
echo "target=$(echo ${GITHUB_BASE_REF} | cut -c -63 | sed -E 's/[^a-z0-9-]+/-/g' | sed -E 's/^-*([a-z0-9-]+[a-z0-9])-*$$/\1/g')" >> $GITHUB_OUTPUT
echo "branch=$(echo ${{ github.ref }} | perl -pE 's|.*?/.*?/||g' | cut -c -63 | sed -E 's/[^a-z0-9-]+/-/g' | sed -E 's/^-*([a-z0-9-]+[a-z0-9])-*$$/\1/g')" >> $GITHUB_OUTPUT
- name: Fetch branches
run: |
if [ ! -z ${{ steps.branches.outputs.target }} ]; then
git fetch origin ${GITHUB_BASE_REF}
else
git fetch origin ${{ github.event.before }}
fi
- name: Container tag
id: container_tag
run: |
BASE=${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_REPOSITORY }}/${{ inputs.image_name }}
if [ ! -z ${{ steps.branches.outputs.target }} ]; then
echo "tag=$BASE:${{ steps.branches.outputs.source }}" >> $GITHUB_OUTPUT
echo "prev_tag=$BASE:${{ steps.branches.outputs.target }}" >> $GITHUB_OUTPUT
else
echo "tag=$BASE:${{ steps.branches.outputs.branch }}" >> $GITHUB_OUTPUT
echo "prev_tag=$BASE:${{ steps.branches.outputs.branch }}" >> $GITHUB_OUTPUT
fi
- name: Dockerfile changed
id: dockerfile
run: |
DIFF=""
if [ -z "${GITHUB_BASE_REF}" ]; then
DIFF="${{ github.event.before }}"
else
DIFF="origin/${GITHUB_BASE_REF}"
fi
if [ -n "$(git diff --name-only HEAD $DIFF -- ${{ inputs.dockerfile }})" ];
then
echo 'changed=True' >> $GITHUB_OUTPUT
fi
- name: Docker prev build
id: docker_prev_build
if: steps.dockerfile.outputs.changed != 'True'
run: |
if docker buildx imagetools create -t ${{ steps.container_tag.outputs.tag }} \
${{ steps.container_tag.outputs.prev_tag }} ;
then
echo 'Successfully synced image'
echo 'exists=True' >> $GITHUB_OUTPUT
fi
- name: Build Testing docker image
uses: docker/build-push-action@v4
if: steps.dockerfile.outputs.changed == 'True' || steps.docker_prev_build.outputs.exists != 'True'
with:
push: true
file: ${{ inputs.dockerfile }}
tags: ${{ steps.container_tag.outputs.tag }}