diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index d9b1a0a..edbdcd9 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -1,59 +1,155 @@ name: "ethereum-writer-deployer" on: - push: - branches: - - '**' + pull_request: + branches: + - master + types: + - opened + - synchronize + - reopened + - edited + - labeled release: types: [ published ] jobs: - build-and-test: + build: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Print tooling versions + run: | + node --version + npm --version + docker --version + python --version + - name: Run npm ci + run: npm ci + - run: npm run build + - name: Upload build artifact + uses: actions/upload-artifact@v3 + with: + name: build + path: ./dist + + test: + needs: build + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v3 + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Download build artifact + uses: actions/download-artifact@v3 + with: + name: build + path: ./dist + - run: npm install --no-save tap-xunit + - run: mkdir -p _out/unit _out/e2e + - run: npm test -- --timeout=1m + + create-version-file: runs-on: ubuntu-latest steps: - name: Check out repository uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Setup node - uses: actions/setup-node@v3 + - name: Determine next version + id: getVersion + uses: Luke-Rogerson/pr-bump-version@v1 + - name: Write version to file + run: | + echo "Outputted version is ${{ steps.getVersion.outputs.version }}" + echo ${{ steps.getVersion.outputs.version }} > .version + - name: Upload .version file as artifact + uses: actions/upload-artifact@v3 with: - node-version: 16 - - name: setup-docker - uses: docker-practice/actions-setup-docker@master - - run: node --version - - run: npm --version - - run: docker --version - - run: python --version - - run: env - - name: Run npm install - run: npm install - - run: npm install --no-save tap-xunit - - run: mkdir -p _out/unit _out/e2e - - run: npm test -- --timeout=1m - - run: npm run build - - build-and-release-to-staging: + name: version + path: .version + + + release-to-staging: + needs: + - build + - test + - create-version-file runs-on: ubuntu-latest steps: - name: Check out repository uses: actions/checkout@v3 + - name: Setup Docker + uses: docker-practice/actions-setup-docker@master + + - name: Download build artifact + uses: actions/download-artifact@v3 with: - fetch-depth: 0 - - name: Setup node - uses: actions/setup-node@v3 + name: build + path: ./dist + + - name: Download version artifact + uses: actions/download-artifact@v3 + with: + name: version + path: ./ + + - name: Login to Docker Hub + uses: docker/login-action@v2 with: - node-version: 16 - - name: setup-docker + username: ${{ secrets.DOCKER_HUB_STAGING_LOGIN }} + password: ${{ secrets.DOCKER_HUB_STAGING_PASSWORD }} + + - name: Build and push image + run: | + echo "Tagging image with $(cat .version)" + docker buildx build --platform linux/amd64,linux/arm64 -t orbsnetworkstaging/ethereum-writer:$(cat .version) --push . + + + release-to-staging-immediate: + if: github.event_name == 'pull_request' && github.event.label.name == 'immediate' + needs: + - build + - test + - create-version-file + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v3 + - name: Setup Docker uses: docker-practice/actions-setup-docker@master - - run: ./boyar/create-version-file.sh - - name: Run npm install - run: npm install - - run: ./boyar/docker-build.sh - - name: release-to-docker-hub-staging - env: - DOCKER_HUB_IMAGE_PATH: orbsnetworkstaging/ethereum-writer - DOCKER_HUB_LOGIN: ${{ secrets.DOCKER_HUB_STAGING_LOGIN }} - DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_STAGING_PASSWORD }} - run: ./.github/release-to-staging.sh + - name: Download build artifact + uses: actions/download-artifact@v3 + with: + name: build + path: ./dist + + - name: Download version artifact + uses: actions/download-artifact@v3 + with: + name: version + path: ./ + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_STAGING_LOGIN }} + password: ${{ secrets.DOCKER_HUB_STAGING_PASSWORD }} + + - name: Build and push image + + run: | + IMMEDIATE_VERSION=$(awk -F'-' '{print $1"-immediate"}' .version) + echo "Tagging image with $IMMEDIATE_VERSION" + docker buildx build --platform linux/amd64,linux/arm64 -t orbsnetworkstaging/ethereum-writer:$IMMEDIATE_VERSION --push . diff --git a/Dockerfile b/Dockerfile index c555eaa..9dfa205 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,12 +7,9 @@ WORKDIR /opt/orbs COPY package*.json ./ COPY .version ./version -RUN apk add --no-cache git +# Add daemontools as a requirement from the ethereum-writer Dockerfile +RUN apk add --no-cache git daemontools --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing -# see https://github.com/nodejs/docker-node/issues/282 - -# --no-cache: download package index on-the-fly, no need to cleanup afterwards -# --virtual: bundle packages, remove whole bundle at once, when done RUN apk --no-cache --virtual build-dependencies add \ python3 \ make \ @@ -20,8 +17,12 @@ RUN apk --no-cache --virtual build-dependencies add \ && npm install \ && apk del build-dependencies -RUN npm install +COPY ./healthcheck/healthcheck ./ +COPY ./healthcheck/healthcheck.js ./ +COPY ./healthcheck/entrypoint.sh /opt/orbs/service + +HEALTHCHECK CMD /opt/orbs/healthcheck COPY dist ./dist -CMD [ "npm", "start" ] +CMD [ "npm", "start" ] \ No newline at end of file diff --git a/boyar/Dockerfile b/boyar/Dockerfile deleted file mode 100644 index d5bbc1a..0000000 --- a/boyar/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM local/ethereum-writer - -RUN apk add --no-cache daemontools --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing - -COPY ./healthcheck ./ -COPY ./healthcheck.js ./ -COPY ./entrypoint.sh /opt/orbs/service - -HEALTHCHECK CMD /opt/orbs/healthcheck diff --git a/boyar/docker-build.sh b/boyar/docker-build.sh deleted file mode 100755 index 4f194c9..0000000 --- a/boyar/docker-build.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -npm run build -docker build -t orbsnetworkstaging/ethereum-writer:$(cat .version) ./boyar diff --git a/boyar/create-version-file.sh b/create-version-file.sh similarity index 100% rename from boyar/create-version-file.sh rename to create-version-file.sh diff --git a/boyar/entrypoint.sh b/healthcheck/entrypoint.sh similarity index 100% rename from boyar/entrypoint.sh rename to healthcheck/entrypoint.sh diff --git a/boyar/healthcheck b/healthcheck/healthcheck similarity index 100% rename from boyar/healthcheck rename to healthcheck/healthcheck diff --git a/boyar/healthcheck.js b/healthcheck/healthcheck.js similarity index 100% rename from boyar/healthcheck.js rename to healthcheck/healthcheck.js diff --git a/package.json b/package.json index c879c12..1fd7020 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "pretest": "npm run typecheck && npm run lint", "clean": "rimraf ./dist/", "prebuild": "npm run clean", - "build": "tsc --skipLibCheck -p ./tsconfig.prod.json && ./boyar/create-version-file.sh && docker build -t local/ethereum-writer .", + "build": "tsc --skipLibCheck -p ./tsconfig.prod.json && ./create-version-file.sh && docker build -t local/ethereum-writer .", "build:quick": "tsc --skipLibCheck -p ./tsconfig.prod.json", "test": "ava --verbose --serial", "test:quick": "echo '-- TEST --' && ava --verbose", @@ -65,4 +65,4 @@ "web3": "1.2.6", "yargs": "^15.3.1" } -} +} \ No newline at end of file