Skip to content

Commit

Permalink
TMP: push artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Jun 26, 2024
1 parent b0bf784 commit fd995ef
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 37 deletions.
61 changes: 27 additions & 34 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
name: 'Docker Build'
description: 'Builds docker image'
inputs:
push:
required: true
description: "Build and push image to registry (cannot be used together with load)"
default: "false"
password:
required: false
description: "Password for the registry"
username:
required: false
description: "Username for the registry"
node_env:
required: false
description: "Node environment"
Expand All @@ -30,9 +20,9 @@ outputs:
image:
description: "The Docker image"
value: ${{ steps.image.outputs.image }}
image_version:
tag:
description: "Combines image and version to a valid image tag"
value: ${{ steps.image.outputs.image }}:${{ steps.meta.outputs.version }}
value: ${{ steps.tag.outputs.tag }}

runs:
using: "composite"
Expand All @@ -46,28 +36,11 @@ runs:
version: latest
buildkitd-flags: --debug

# Login to a registry to push the image
- name: Login to Container Registry
# Only login if we are pushing the image
if: ${{ inputs.push == 'true' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ inputs.username }}
password: ${{ inputs.password }}

- name: Docker Image
id: image
shell: bash
run: |
registry="ghcr.io"
repository="${{ github.repository }}"
image="$registry/$repository"
echo "registry=$registry" >> $GITHUB_OUTPUT
echo "repository=$repository" >> $GITHUB_OUTPUT
echo "image=$image" >> $GITHUB_OUTPUT
echo "image=${{ github.repository }}" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Docker meta
Expand Down Expand Up @@ -100,15 +73,35 @@ runs:
cat $GITHUB_OUTPUT
- name: Tar file
id: tar
shell: bash
run: |
echo "path=/tmp/${{ steps.meta.outputs.version }}" >> $GITHUB_OUTPUT
- name: Build Image
id: build
uses: docker/bake-action@v4
env:
DOCKER_TAG: ${{ steps.tag.outputs.tag }}
with:
targets: app
push: ${{ inputs.push }}
load: ${{ inputs.push == 'false' }}
set: |
*.cache-from=type=registry,ref=${{ steps.tag.outputs.tag_cache }}
*.cache-to=type=registry,ref=${{ steps.tag.outputs.tag_cache }},mode=max,compression-level=9,force-compression=true,ignore-error=true
*.output=type=docker,dest=${{ steps.tar.outputs.path }}
- name: Get image digest
id: digest
shell: bash
run: |
echo '${{ steps.build.outputs.metadata }}' > metadata.json
echo "digest=$(cat metadata.json | jq -r '.app."containerimage.digest"')" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.meta.outputs.version }}
path: ${{ steps.tar.outputs.path }}
retention-days: 1
compression-level: 9
overwrite: true
27 changes: 27 additions & 0 deletions .github/actions/push/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'Docker Push image to registry'
description: 'Pushes build docker image to registry'
inputs:
tag:
required: true
description: "The full docker tag to push"
password:
required: false
description: "Password for the registry"
username:
required: false
description: "Username for the registry"

runs:
using: "composite"
steps:
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ inputs.username }}
password: ${{ inputs.password }}

- name: Push Image
shell: bash
run: |
docker image push ${{ inputs.tag }}
37 changes: 34 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,53 @@ on:
permissions:
packages: write

# TODO:
# 1. split out the push action to separate action
# 2. add caching based on fork behaviour, use GHA cache or registry..

jobs:
build:
runs-on: ubuntu-latest

outputs:
version: ${{ steps.build.outputs.version }}

steps:
- uses: actions/checkout@v4

- id: context
uses: ./.github/actions/context

- uses: ./.github/actions/build
id: build
with:
push: true
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
node_env: production
latest: ${{ steps.context.outputs.is_release_master }}

- uses: ./.github/actions/push
if: steps.context.outputs.is_fork == 'false'
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.build.outputs.tag }}

download:
runs-on: ubuntu-latest
needs: [build]

steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.version }}
path: /tmp/

- name: Load image
shell: bash
run: |
docker load < /tmp/${{ needs.build.outputs.version }}
docker image ls

0 comments on commit fd995ef

Please sign in to comment.