Skip to content
Latchkey

Release & Docker workflow (chrisleekr/binance-trading-bot)

The Release & Docker workflow from chrisleekr/binance-trading-bot, explained and optimized by Latchkey.

B

CI health: B - good

Point runs-on at Latchkey and get job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: chrisleekr/binance-trading-bot.github/workflows/release-and-docker.ymlLicense MITView source

What it does

This is the Release & Docker workflow from the chrisleekr/binance-trading-bot repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Release & Docker

on:
  repository_dispatch:
    types: [Release & Docker]
  workflow_dispatch:

jobs:
  create-release:
    name: Create Release
    runs-on: ubuntu-latest
    steps:
      - name: Create Release
        id: create_release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ github.event.client_payload.ref }}
          name:
            '<Update release name for ${{ github.event.client_payload.ref }}>'
          draft: true
          prerelease: false
          generate_release_notes: true

  docker-images:
    name: Build/Push production docker image
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.client_payload.ref }}

      # https://github.com/docker/setup-qemu-action#usage
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1

      # https://github.com/marketplace/actions/docker-setup-buildx
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      # https://github.com/docker/login-action#docker-hub
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Get build args
        run: |
          echo "PACKAGE_VERSION=$(grep -m1 version package.json | cut -c 15- | rev | cut -c 3- | rev)" >> $GITHUB_ENV
          echo "GIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

      # https://github.com/docker/build-push-action#multi-platform-image
      - name: Build/Push production docker image
        uses: docker/build-push-action@v2
        with:
          context: .
          file: Dockerfile
          platforms: linux/amd64,linux/arm/v7,linux/arm64
          push: true
          target: production-stage
          build-args: |
            PACKAGE_VERSION=${{ env.PACKAGE_VERSION }}
            GIT_HASH=${{ env.GIT_HASH }}
            NODE_ENV=production
          tags: |
            chrisleekr/binance-trading-bot:latest
            chrisleekr/binance-trading-bot:${{ env.PACKAGE_VERSION }}

      # https://github.com/docker/build-push-action#multi-platform-image
      - name: Build/Push production docker image - tradingview
        uses: docker/build-push-action@v2
        with:
          context: ./tradingview
          file: ./tradingview/Dockerfile
          platforms: linux/amd64,linux/arm/v7,linux/arm64
          push: true
          tags: |
            chrisleekr/binance-trading-bot:tradingview
            chrisleekr/binance-trading-bot:tradingview-${{ env.PACKAGE_VERSION }}

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Release & Docker
 
on:
  repository_dispatch:
    types: [Release & Docker]
  workflow_dispatch:
 
jobs:
  create-release:
    timeout-minutes: 30
    name: Create Release
    runs-on: latchkey-small
    steps:
      - name: Create Release
        id: create_release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ github.event.client_payload.ref }}
          name:
            '<Update release name for ${{ github.event.client_payload.ref }}>'
          draft: true
          prerelease: false
          generate_release_notes: true
 
  docker-images:
    timeout-minutes: 30
    name: Build/Push production docker image
    runs-on: latchkey-small
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.client_payload.ref }}
 
      # https://github.com/docker/setup-qemu-action#usage
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
 
      # https://github.com/marketplace/actions/docker-setup-buildx
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
 
      # https://github.com/docker/login-action#docker-hub
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
 
      - name: Get build args
        run: |
          echo "PACKAGE_VERSION=$(grep -m1 version package.json | cut -c 15- | rev | cut -c 3- | rev)" >> $GITHUB_ENV
          echo "GIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
 
      # https://github.com/docker/build-push-action#multi-platform-image
      - name: Build/Push production docker image
        uses: docker/build-push-action@v2
        with:
          context: .
          file: Dockerfile
          platforms: linux/amd64,linux/arm/v7,linux/arm64
          push: true
          target: production-stage
          build-args: |
            PACKAGE_VERSION=${{ env.PACKAGE_VERSION }}
            GIT_HASH=${{ env.GIT_HASH }}
            NODE_ENV=production
          tags: |
            chrisleekr/binance-trading-bot:latest
            chrisleekr/binance-trading-bot:${{ env.PACKAGE_VERSION }}
 
      # https://github.com/docker/build-push-action#multi-platform-image
      - name: Build/Push production docker image - tradingview
        uses: docker/build-push-action@v2
        with:
          context: ./tradingview
          file: ./tradingview/Dockerfile
          platforms: linux/amd64,linux/arm/v7,linux/arm64
          push: true
          tags: |
            chrisleekr/binance-trading-bot:tradingview
            chrisleekr/binance-trading-bot:tradingview-${{ env.PACKAGE_VERSION }}
 

What changed

5 third-party actions are referenced by a movable tag. Pin them to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 2 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow