Skip to content

Commit

Permalink
Build & push images to both registries at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Silex committed Aug 16, 2024
1 parent 6ab5837 commit 9eac077
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
28 changes: 9 additions & 19 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ inputs:
runs:
using: composite
steps:
- name: Login to docker.io
uses: docker/login-action@master
with:
username: ${{ fromJSON(inputs.secrets).DOCKERHUB_USERNAME }}
password: ${{ fromJSON(inputs.secrets).DOCKERHUB_TOKEN }}

- name: Login to ghcr.io
uses: docker/login-action@master
with:
Expand All @@ -26,29 +32,13 @@ runs:
shell: bash
run: |
echo "tags=$(bin/images --json | jq -c '.images[] | select(.version == "${{ inputs.version }}" and .context == "${{ inputs.context }}") | .tags_with_repository')" >> $GITHUB_OUTPUT
echo "ghcr_tags=$(bin/images --json | jq -c '.images[] | select(.version == "${{ inputs.version }}" and .context == "${{ inputs.context }}") | .ghcr_tags_with_repository')" >> $GITHUB_OUTPUT
- name: Build & push image to ghcr.io
- name: Build & push images
uses: docker/build-push-action@master
with:
pull: true
push: ${{ github.ref == 'refs/heads/master' }}
tags: ${{ join(fromJSON(steps.data.outputs.ghcr_tags), ', ') }}
context: images/${{ inputs.version }}/${{ inputs.context }}
cache-from: type=registry,ref=${{ fromJSON(steps.data.outputs.ghcr_tags)[0] }}-cache
cache-to: type=registry,ref=${{ fromJSON(steps.data.outputs.ghcr_tags)[0] }}-cache,mode=max

- name: Login to Docker Hub
uses: docker/login-action@master
with:
username: ${{ fromJSON(inputs.secrets).DOCKERHUB_USERNAME }}
password: ${{ fromJSON(inputs.secrets).DOCKERHUB_TOKEN }}

- name: Push image to Docker Hub
uses: docker/build-push-action@master
with:
pull: false
push: ${{ github.ref == 'refs/heads/master' }}
cache-from: ${{ fromJSON(steps.data.outputs.ghcr_tags)[0] }}-cache
tags: ${{ join(fromJSON(steps.data.outputs.tags), ', ') }}
context: images/${{ inputs.version }}/${{ inputs.context }}
cache-from: type=registry,ref=${{ fromJSON(steps.data.outputs.tags)[0] }}-cache
cache-to: type=registry,ref=${{ fromJSON(steps.data.outputs.tags)[0] }}-cache,mode=max
10 changes: 4 additions & 6 deletions bin/images
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Image
attr_reader :version
attr_reader :context

REGISTRIES = %w[ghcr.io docker.io]
REPOSITORY = 'silex/emacs'

class << self
Expand Down Expand Up @@ -101,7 +102,6 @@ class Image
directory: directory,
tags: tags,
tags_with_repository: tags_with_repository,
ghcr_tags_with_repository: ghcr_tags_with_repository,
depends: depends,
depends_with_repository: depends_with_repository,
children: children
Expand All @@ -119,11 +119,9 @@ class Image
end

def tags_with_repository
tags.map{ |s| format('%s:%s', REPOSITORY, s) }
end

def ghcr_tags_with_repository
tags_with_repository.map{ |s| format('ghcr.io/%s', s) }
REGISTRIES.map do |registry|
tags.map{ |s| format('%s/%s:%s', registry, REPOSITORY, s) }
end.flatten
end

def depends
Expand Down

0 comments on commit 9eac077

Please sign in to comment.