From 1b66139c7c7f787bf4668b1c3e83b3ba2212d842 Mon Sep 17 00:00:00 2001 From: nugaon <50576770+nugaon@users.noreply.github.com> Date: Tue, 4 May 2021 14:48:36 +0200 Subject: [PATCH] ci: init (#5) * feat: build docker images with one script * feat: publish the built docker image * ci: init worflow to publish built docker image * chore: add the new commands to the package.json * ci: add npm setup command run * ci: build with only node 12.x * refactor: add github repo bee image prefix to .env * ci: github action input for build docker image * fix: intend in yaml * fix: typeo * fix: testing the rumor about github bug in order to show up the run workflow button * revert: prev commit - did not work * ci: only build image if it was clicked manually --- .github/workflows/publish.yaml | 43 ++++++++++++++++++++++++++++++++++ package.json | 6 +++-- scripts/.env | 2 +- scripts/build-environment.sh | 10 ++++++++ scripts/publish-environment.sh | 10 ++++++++ 5 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/publish.yaml create mode 100755 scripts/build-environment.sh create mode 100755 scripts/publish-environment.sh diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..5e6dcf7 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,43 @@ +on: + workflow_dispatch: + inputs: + buildImage: + description: 'Build Docker Image according to the environment' + default: 'false' + push: + branches: + - 'master' + pull_request: + branches: + - '**' + +env: + BEE_IMAGE_PREFIX: 'docker.pkg.github.com/ethersphere/bee-factory' + +jobs: + bee-images: + name: Build and publish images + runs-on: ubuntu-latest + steps: + - uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: 'https://registry.npmjs.org' + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 1 + - name: Auth to Github Package Docker Registry + if: (github.ref == 'refs/heads/master' || ${{ github.event.inputs.buildImage }} == 'true') && success() + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://docker.pkg.github.com -u ${GITHUB_ACTOR} --password-stdin + - name: Install npm deps + if: steps.cache-npm.outputs.cache-hit != 'true' + run: npm ci + - name: Build images + run: | + npm run build:env + - name: Publish if it was clicked manually + if: ${{ github.event.inputs.buildImage }} == 'true' && success() + run: | + npm run publish:env diff --git a/package.json b/package.json index 9aa0ee9..acd508a 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,10 @@ "scripts": { "compile:chequebook": "truffle compile", "migrate:chequebook": "truffle migrate", - "test:chequebook": "truffle test", - "supply": "truffle exec src/supply.js" + "supply": "truffle exec src/supply.js", + "build:env": "./scripts/build-environment.sh", + "publish:env": "./scripts/publish-environment.sh", + "run:env": "./scripts/environment.sh" }, "dependencies": { "@openzeppelin/contracts": "^3.1.0", diff --git a/scripts/.env b/scripts/.env index b2213c6..7ead315 100755 --- a/scripts/.env +++ b/scripts/.env @@ -1,4 +1,4 @@ BEE_VERSION="0.5.3" BLOCKCHAIN_VERSION="1.0.0" BEE_ENV_PREFIX="swarm-test" -BEE_IMAGE_PREFIX=ethersphere +BEE_IMAGE_PREFIX="docker.pkg.github.com/ethersphere/bee-factory" diff --git a/scripts/build-environment.sh b/scripts/build-environment.sh new file mode 100755 index 0000000..4899cb3 --- /dev/null +++ b/scripts/build-environment.sh @@ -0,0 +1,10 @@ +#!/bin/bash +MY_PATH=$(dirname "$0") +MY_PATH=$( cd "$MY_PATH" && pwd ) + +"$MY_PATH/network.sh" +"$MY_PATH/blockchain.sh" +npm run migrate:chequebook +npm run supply +"$MY_PATH/blockchain-docker-build.sh" +"$MY_PATH/bee-docker-build.sh" diff --git a/scripts/publish-environment.sh b/scripts/publish-environment.sh new file mode 100755 index 0000000..9cca9c5 --- /dev/null +++ b/scripts/publish-environment.sh @@ -0,0 +1,10 @@ +#!/bin/bash +MY_PATH=$(dirname "$0") +MY_PATH=$( cd "$MY_PATH" && pwd ) + +DOCKER_IMAGES=$(docker image ls -qaf reference="$BEE_IMAGE_PREFIX/$BEE_ENV_PREFIX*:$BEE_VERSION") +for DOCKER_IMAGE in $DOCKER_IMAGES +do + echo "$DOCKER_IMAGE" + docker push "$DOCKER_IMAGE" +done