Skip to content

Commit

Permalink
chore: extract docker flow to separate workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Jan 25, 2025
1 parent b17dff4 commit 99b47c3
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 131 deletions.
137 changes: 6 additions & 131 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,135 +93,10 @@ jobs:
with:
asset_paths: '["./freqUI.zip"]'


docker:
if: (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'release') && github.repository == 'freqtrade/frequi'
call-docker-workflow:
needs: build
runs-on: ubuntu-latest

permissions:
packages: write

environment:
name: Production
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm/v6
- linux/arm/v7
- linux/arm64

steps:

- uses: actions/checkout@v4

- name: Prepare Platform_pair
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}


- name: Download digests
uses: actions/download-artifact@v4
with:
path: ./dist/
# Use node-22 build.
name: freqUI-22


- name: Build and push Docker image
id: build
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
context: .
file: ./docker/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
outputs: type=image,name=freqtradeorg/frequi,push-by-digest=true,name-canonical=true,push=true


- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

docker-merge:
runs-on: ubuntu-latest
needs:
- docker
environment:
name: Production

permissions:
packages: write

steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
freqtradeorg/frequi
ghcr.io/freqtrade/frequi
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=semver,pattern={{version}}
type=ref,event=branch
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf 'freqtradeorg/frequi@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect freqtradeorg/frequi:${{ steps.meta.outputs.version }}
if: (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'release') && github.repository == 'freqtrade/frequi'
uses: ./.github/workflows/docker.yml
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
133 changes: 133 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: FreqUI Docker Build

on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true

jobs:
docker:
runs-on: ubuntu-latest
permissions:
packages: write
environment:
name: Production
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm/v6
- linux/arm/v7
- linux/arm64

steps:
- uses: actions/checkout@v4

- name: Prepare Platform_pair
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Download digests
uses: actions/download-artifact@v4
with:
path: ./dist/
# Use node-22 build.
name: freqUI-22

- name: Build and push Docker image
id: build
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
context: .
file: ./docker/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
outputs: type=image,name=freqtradeorg/frequi,push-by-digest=true,name-canonical=true,push=true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

docker-merge:
runs-on: ubuntu-latest
needs:
- docker
environment:
name: Production
permissions:
packages: write

steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
freqtradeorg/frequi
ghcr.io/freqtrade/frequi
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=semver,pattern={{version}}
type=ref,event=branch
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf 'freqtradeorg/frequi@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect freqtradeorg/frequi:${{ steps.meta.outputs.version }}

0 comments on commit 99b47c3

Please sign in to comment.