Update Github Actions - build docker image and deploy to Github registry #31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: tokenbridge | |
on: [push] | |
env: | |
DOCKER_REGISTRY: docker.pkg.github.com | |
DOCKER_REPO: gnosischain/tokenbridge | |
DOCKER_IMAGE_BASE: docker.pkg.github.com/gnosischain/tokenbridge | |
jobs: | |
initialize: | |
runs-on: ubuntu-latest | |
outputs: | |
cache_key: ${{ steps.get_cache_key.outputs.cache_key }} | |
steps: | |
- uses: actions/setup-node@v1 | |
with: | |
node-version: 12 | |
- uses: actions/checkout@v2 | |
with: | |
submodules: true | |
- name: Set cache key | |
id: get_cache_key | |
run: | | |
git submodule status > submodule.status | |
echo "::set-output name=cache_key::cache-repo-${{ hashFiles('yarn.lock', 'package.json', 'submodule.status') }}" | |
- uses: actions/cache@v2 | |
id: cache-repo | |
with: | |
path: | | |
**/node_modules | |
contracts/build | |
key: ${{ steps.get_cache_key.outputs.cache_key }} | |
- name: Install dependencies and compile contracts | |
if: ${{ !steps.cache-repo.outputs.cache-hit }} | |
run: | | |
yarn install --frozen-lockfile | |
yarn run install:deploy | |
yarn run compile:contracts | |
validate: | |
runs-on: ubuntu-latest | |
needs: | |
- initialize | |
strategy: | |
fail-fast: false | |
matrix: | |
task: [build, lint, test] | |
steps: | |
- uses: actions/setup-node@v1 | |
with: | |
node-version: 12 | |
- uses: actions/checkout@v2 | |
with: | |
submodules: true | |
- uses: actions/cache@v2 | |
id: cache-repo | |
with: | |
path: | | |
**/node_modules | |
contracts/build | |
key: ${{ needs.initialize.outputs.cache_key }} | |
- name: yarn run ${{ matrix.task }} | |
run: ${{ steps.cache-repo.outputs.cache-hit }} && yarn run ${{ matrix.task }} | |
build-e2e-images: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
submodules: true | |
- name: Evaluate e2e docker images tags | |
run: | | |
git submodule status > submodule.status | |
echo "E2E_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'Dockerfile.e2e', 'commons', 'oracle-e2e', 'monitor-e2e', 'e2e-commons') }}" >> $GITHUB_ENV | |
echo "ORACLE_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'commons', 'oracle') }}" >> $GITHUB_ENV | |
echo "MONITOR_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'commons', 'monitor') }}" >> $GITHUB_ENV | |
echo "ALM_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'commons', 'alm') }}" >> $GITHUB_ENV | |
- name: Rebuild and push updated images | |
run: | | |
function check_if_image_exists() { | |
curl -fsSlL "https://${{ github.actor }}:${{ github.token }}@${DOCKER_REGISTRY}/v2/${DOCKER_REPO}/tokenbridge-e2e-$1/manifests/$2" > /dev/null | |
} | |
updated=() | |
if ! check_if_image_exists e2e ${E2E_TAG}; then updated+=("e2e"); fi | |
if ! check_if_image_exists oracle ${ORACLE_TAG}; then updated+=("oracle-amb"); fi | |
if ! check_if_image_exists monitor ${MONITOR_TAG}; then updated+=("monitor-amb"); fi | |
if ! check_if_image_exists alm ${ALM_TAG}; then updated+=("alm"); fi | |
if [ ${#updated[@]} -gt 0 ]; then | |
echo "Updated services: ${updated[@]}" | |
cd e2e-commons | |
docker login ${DOCKER_REGISTRY} -u ${{ github.actor }} -p ${{ github.token }} | |
docker-compose build ${updated[@]} | |
docker-compose push ${updated[@]} | |
else | |
echo "Nothing relevant was changed in the source" | |
fi | |
build-molecule-runner: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
submodules: true | |
- name: Evaluate e2e molecule runner tag | |
run: echo "MOLECULE_RUNNER_TAG=${{ hashFiles('./deployment-e2e/Dockerfile') }}" >> $GITHUB_ENV | |
- name: Rebuild and push molecule runner e2e image | |
run: | | |
function check_if_image_exists() { | |
curl -fsSlL "https://${{ github.actor }}:${{ github.token }}@${DOCKER_REGISTRY}/v2/${DOCKER_REPO}/tokenbridge-e2e-$1/manifests/$2" > /dev/null | |
} | |
if check_if_image_exists molecule_runner ${MOLECULE_RUNNER_TAG}; then | |
echo "Image already exists" | |
else | |
cd e2e-commons | |
docker login ${DOCKER_REGISTRY} -u ${{ github.actor }} -p ${{ github.token }} | |
docker-compose build molecule_runner | |
docker-compose push molecule_runner | |
fi | |
e2e: | |
runs-on: ubuntu-latest | |
needs: | |
- initialize | |
- build-e2e-images | |
strategy: | |
fail-fast: false | |
matrix: | |
task: [oracle-e2e, monitor-e2e, alm-e2e] | |
include: | |
- task: alm-e2e | |
use-cache: true | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
submodules: true | |
- name: Evaluate e2e docker images tags | |
run: | | |
git submodule status > submodule.status | |
echo "E2E_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'Dockerfile.e2e', 'commons', 'oracle-e2e', 'monitor-e2e', 'e2e-commons') }}" >> $GITHUB_ENV | |
echo "ORACLE_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'commons', 'oracle') }}" >> $GITHUB_ENV | |
echo "MONITOR_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'commons', 'monitor') }}" >> $GITHUB_ENV | |
echo "ALM_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'commons', 'alm') }}" >> $GITHUB_ENV | |
- if: ${{ matrix.use-cache }} | |
uses: actions/cache@v2 | |
id: cache-repo | |
with: | |
path: | | |
**/node_modules | |
contracts/build | |
key: ${{ needs.initialize.outputs.cache_key }} | |
- name: Login to docker registry | |
run: docker login ${DOCKER_REGISTRY} -u ${{ github.actor }} -p ${{ github.token }} | |
- name: yarn run ${{ matrix.task }} | |
run: ${{ !matrix.use-cache || steps.cache-repo.outputs.cache-hit }} && yarn run ${{ matrix.task }} | |
- name: Upload logs | |
if: always() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: logs-${{ matrix.task }} | |
path: e2e-commons/logs | |
deployment: | |
runs-on: ubuntu-latest | |
needs: | |
- build-e2e-images | |
- build-molecule-runner | |
strategy: | |
fail-fast: false | |
matrix: | |
task: [oracle, monitor, multiple, repo] | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
submodules: true | |
- name: Evaluate e2e molecule runner tag | |
run: echo "MOLECULE_RUNNER_TAG=${{ hashFiles('./deployment-e2e/Dockerfile') }}" >> $GITHUB_ENV | |
- name: Login to docker registry | |
run: docker login ${DOCKER_REGISTRY} -u ${{ github.actor }} -p ${{ github.token }} | |
- run: deployment-e2e/molecule.sh ${{ matrix.task }} | |
ultimate: | |
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags') || contains(github.event.head_commit.message, 'ultimate') | |
runs-on: ubuntu-latest | |
needs: | |
- initialize | |
- build-e2e-images | |
strategy: | |
fail-fast: false | |
matrix: | |
task: [amb, erc-to-native] | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
submodules: true | |
- name: Evaluate e2e docker images tags | |
run: | | |
git submodule status > submodule.status | |
echo "E2E_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'Dockerfile.e2e', 'commons', 'oracle-e2e', 'monitor-e2e', 'e2e-commons') }}" >> $GITHUB_ENV | |
echo "ORACLE_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'commons', 'oracle') }}" >> $GITHUB_ENV | |
echo "MONITOR_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'commons', 'monitor') }}" >> $GITHUB_ENV | |
echo "ALM_TAG=${{ hashFiles('yarn.lock', 'package.json', 'submodule.status', 'commons', 'alm') }}" >> $GITHUB_ENV | |
echo "MOLECULE_RUNNER_TAG=${{ hashFiles('./deployment-e2e/Dockerfile') }}" >> $GITHUB_ENV | |
- uses: actions/cache@v2 | |
id: cache-repo | |
with: | |
path: | | |
**/node_modules | |
contracts/build | |
key: ${{ needs.initialize.outputs.cache_key }} | |
- name: Login to docker registry | |
run: docker login ${DOCKER_REGISTRY} -u ${{ github.actor }} -p ${{ github.token }} | |
- name: Deploy contracts | |
run: ${{ steps.cache-repo.outputs.cache-hit }} && e2e-commons/up.sh deploy generate-amb-tx blocks | |
- name: Pull e2e oracle image | |
run: | | |
docker-compose -f ./e2e-commons/docker-compose.yml pull oracle-amb | |
docker tag ${DOCKER_IMAGE_BASE}/tokenbridge-e2e-oracle:${ORACLE_TAG} gnosischain/tokenbridge-oracle:latest | |
- name: Deploy oracle | |
run: deployment-e2e/molecule.sh ultimate-${{ matrix.task }} | |
- name: Reset docker socket permissions | |
run: sudo chown -R $USER:docker /var/run/docker.sock | |
- name: Run oracle e2e tests | |
run: docker-compose -f ./e2e-commons/docker-compose.yml run -e ULTIMATE=true e2e yarn workspace oracle-e2e run ${{ matrix.task }} | |
- name: Save logs | |
if: always() | |
run: e2e-commons/down.sh | |
- name: Upload logs | |
if: always() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: logs-ultimate-${{ matrix.task }} | |
path: e2e-commons/logs |