-
Notifications
You must be signed in to change notification settings - Fork 44
119 lines (100 loc) · 4.22 KB
/
build.yaml
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
name: build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
version:
- '0.21'
- '0.18'
- '0.17'
- '0.16'
- '0.15'
- '0.14'
- '0.13'
- '0.10'
fail-fast: false
steps:
- name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v1
- name: Checkout
uses: actions/checkout@v2
- name: Prepare Docker build
id: prepare
run: |
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
LITECOIN_VERSION=${{matrix.version}}
LATEST_LITECOIN_MAJOR_VERSION=$(ls | grep 0 | sort -n | tail -n 1)
PLATFORMS="linux/amd64"
PUSH=false
REPO=uphold/litecoin-core
TAGS=()
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
PUSH=true
if [[ ${LITECOIN_VERSION} == *"alpine"* ]]; then
TAGS+=("$REPO:$TAG-alpine")
else
TAGS+=("$REPO:$TAG")
fi
TAG_MAJOR_MINOR=$(echo $TAG | cut -c -4)
if [ $(version ${TAG_MAJOR_MINOR}) -ne $(version ${LITECOIN_VERSION}) ]; then
echo "Skipping build of base image $LITECOIN_VERSION/ as ${TAG} is targeted at ${TAG_MAJOR_MINOR}/"
exit 0
fi
else
TAGS=("$REPO:${LITECOIN_VERSION/\//-}")
if [ $(version ${LITECOIN_VERSION}) -ge $(version ${LATEST_LITECOIN_MAJOR_VERSION}) ]; then
echo "Version $(version ${LITECOIN_VERSION}) is greater than or equal to $(version ${LATEST_LITECOIN_MAJOR_VERSION}), tagging as latest"
if [[ ${LITECOIN_VERSION} != *"alpine"* ]]; then
TAGS+=("$REPO:latest")
else
TAGS+=("$REPO:alpine")
fi
fi
if [ $GITHUB_REF == "refs/heads/master" ]; then
PUSH=true
fi
fi
if [[ ${LITECOIN_VERSION} != *"alpine"* ]] && [ $(version ${LITECOIN_VERSION}) -ge $(version "0.21") ]; then
PLATFORMS="linux/amd64,linux/arm/v7,linux/arm64"
fi
echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=docker_platforms::${PLATFORMS}
echo ::set-output name=push::${PUSH}
echo ::set-output name=tags::${TAGS[@]}
echo ::set-output name=build::true
- if: ${{ steps.prepare.outputs.build }} == 'true'
name: Login into Docker Hub
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
run: |
echo "${DOCKER_HUB_PASSWORD}" | docker login --username "${DOCKER_HUB_USERNAME}" --password-stdin
- if: ${{ steps.prepare.outputs.build }} == 'true'
name: Build Docker image
run: |
TAGS=(${{ steps.prepare.outputs.tags }})
echo "Build date: ${{ steps.prepare.outputs.build_date }}"
echo "Docker platform: ${{ steps.prepare.outputs.docker_platforms }}"
echo "Push: ${{ steps.prepare.outputs.push }}"
echo "Tags: ${{ steps.prepare.outputs.tags }}"
echo docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
--output "type=image,push=${{steps.prepare.outputs.push}}" \
--progress=plain \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
$(printf "%s" "${TAGS[@]/#/ --tag }" ) \
${{ matrix.version }}/
docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
--output "type=image,push=${{steps.prepare.outputs.push}}" \
--progress=plain \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
$(printf "%s" "${TAGS[@]/#/ --tag }" ) \
${{ matrix.version }}/
- if: ${{ steps.prepare.outputs.build }} == 'true'
name: Clear Docker credentials
run: |
rm -f ${HOME}/.docker/config.json