Skip to content

Commit

Permalink
Merge pull request #75 from morganchristiansson/simplify-retry
Browse files Browse the repository at this point in the history
Extract retry logic into scripts/retry
  • Loading branch information
cytopia authored Jun 2, 2021
2 parents ad46a7d + c463acd commit 4d50c33
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 1,031 deletions.
149 changes: 11 additions & 138 deletions .github/workflows/build-helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,223 +109,96 @@ jobs:
# ------------------------------------------------------------
- name: Pull Base Image
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make pull-base-image
env:
RETRIES: 20
PAUSE: 10
scripts/retry make pull-base-image
- name: Build Builder Image
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make _build_builder
scripts/retry make _build_builder
env:
VERSION: ${{ matrix.version }}
RETRIES: 20
PAUSE: 10


# ------------------------------------------------------------
# Base
# ------------------------------------------------------------
- name: Build Ansible Base
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make build ANSIBLE=${VERSION} FLAVOUR=base
scripts/retry make build ANSIBLE=${VERSION} FLAVOUR=base
env:
VERSION: ${{ matrix.version }}
RETRIES: 20
PAUSE: 10


# ------------------------------------------------------------
# Tools
# ------------------------------------------------------------
- name: Build Ansible Tools
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make build ANSIBLE=${VERSION} FLAVOUR=tools
scripts/retry make build ANSIBLE=${VERSION} FLAVOUR=tools
env:
VERSION: ${{ matrix.version }}
RETRIES: 20
PAUSE: 10


# ------------------------------------------------------------
# AWS
# ------------------------------------------------------------
- name: Build Ansible AWS
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make build ANSIBLE=${VERSION} FLAVOUR=aws
scripts/retry make build ANSIBLE=${VERSION} FLAVOUR=aws
env:
VERSION: ${{ matrix.version }}
RETRIES: 20
PAUSE: 10


# ------------------------------------------------------------
# AWS K8s
# ------------------------------------------------------------
- name: Build Ansible AWS K8s
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make build ANSIBLE=${VERSION} FLAVOUR=awsk8s
scripts/retry make build ANSIBLE=${VERSION} FLAVOUR=awsk8s
env:
VERSION: ${{ matrix.version }}
RETRIES: 20
PAUSE: 10


# ------------------------------------------------------------
# AWS Helm
# ------------------------------------------------------------
- name: Build Ansible AWS Helm
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make build ANSIBLE=${VERSION} FLAVOUR=awshelm HELM=${HELM}
scripts/retry make build ANSIBLE=${VERSION} FLAVOUR=awshelm HELM=${HELM}
env:
HELM: ${{ matrix.helm }}
VERSION: ${{ matrix.version }}
RETRIES: 20
PAUSE: 10

- name: Test Ansible AWS Helm
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make test ANSIBLE=${VERSION} FLAVOUR=awshelm HELM=${HELM}
scripts/retry make test ANSIBLE=${VERSION} FLAVOUR=awshelm HELM=${HELM}
env:
HELM: ${{ matrix.helm }}
VERSION: ${{ matrix.version }}
RETRIES: 20
PAUSE: 10


# ------------------------------------------------------------
# Deploy
# ------------------------------------------------------------
- name: Publish images (only repo owner)
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
# Output
echo "GIT_TYPE=${GIT_TYPE}"
echo "GIT_SLUG=${GIT_SLUG}"
echo "DOCKER_TAG_AWSHELM=${DOCKER_TAG_AWSHELM}"
# Tag image
retry make tag ANSIBLE=${VERSION} FLAVOUR=awshelm HELM=${HELM} TAG=${DOCKER_TAG_AWSHELM}
scripts/retry make tag ANSIBLE=${VERSION} FLAVOUR=awshelm HELM=${HELM} TAG=${DOCKER_TAG_AWSHELM}
docker images | grep cytopia/ansible
# Login
retry make login USERNAME=${{ secrets.DOCKERHUB_USERNAME }} PASSWORD=${{ secrets.DOCKERHUB_PASSWORD }}
scripts/retry make login USERNAME=${{ secrets.DOCKERHUB_USERNAME }} PASSWORD=${{ secrets.DOCKERHUB_PASSWORD }}
# Push
retry make push TAG=${DOCKER_TAG_AWSHELM}
scripts/retry make push TAG=${DOCKER_TAG_AWSHELM}
env:
HELM: ${{ matrix.helm }}
VERSION: ${{ matrix.version }}
RETRIES: 20
PAUSE: 10
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
&& (
Expand Down
Loading

0 comments on commit 4d50c33

Please sign in to comment.