Skip to content

Commit

Permalink
Merge pull request #108 from MusicDin/feat/image-upload
Browse files Browse the repository at this point in the history
Publish images after successful build
  • Loading branch information
tomponline authored Mar 22, 2024
2 parents 21ae9cf + 26d50af commit e13b5ed
Show file tree
Hide file tree
Showing 23 changed files with 217 additions and 70 deletions.
75 changes: 49 additions & 26 deletions .github/actions/image-upload/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,62 @@ name: Upload Image
description: Composite action for uploading built images

inputs:
name:
description: Final image name
required: true
target:
description: Directory where built image is located
required: true
# types:
# description: Image types
# required: true
image_dir:
description: Image directory in format <distro>/<release>/<arch>/<variant>
required: true
ssh_private_key:
description: SSH private key for the image server
required: true

runs:
using: composite
steps:
# actions/upload-artifact does not expand env vars.
- name: Expand target path
- name: Print artifacts
shell: bash
run: echo "target=${{ inputs.target }}" >> $GITHUB_ENV
run: ls -lah "${{ inputs.target }}"

- name: Print artifacts
- name: Configure private key and known host
shell: bash
env:
SSH_HOST: images.lxd.canonical.com
run : |
# Store image server private key.
mkdir -p -m 0700 ~/.ssh
touch ~/.ssh/id_ed25519
chmod 0600 ~/.ssh/id_ed25519
echo "${{ inputs.ssh_private_key }}" > ~/.ssh/id_ed25519
# Configure known host.
echo "${SSH_HOST} ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOJS6V7WpVdFdAcTSn/98rBRsvJVyTI3O17qMeg0cD5E" >> ~/.ssh/known_hosts
- name: Upload artifacts to the image server
shell: bash
run: ls -lah "${{ env.target }}"

- name: Publish artifacts
uses: actions/upload-artifact@v4
with:
name: "${{ inputs.name }}"
path: |
${{ env.target }}/*.qcow2
${{ env.target }}/*.squashfs
${{ env.target }}/*.tar.xz
${{ env.target }}/image.yaml
${{ env.target }}/serial
if-no-files-found: "error"
retention-days: 1
compression-level: 0
overwrite: true
env:
SSH_HOST: images.lxd.canonical.com
SSH_USER: imageserver
SSH_PORT: 922
run: |
# Ensure path of the source directory is expanded.
SRC_DIR=$(echo ${{ inputs.target }})
IMG_DIR=${{ inputs.image_dir }}
VERSION=$(cat "${SRC_DIR}/serial")
# Create directory structure that will be mirrored on the target server.
PRODUCT_PATH="${SRC_DIR}-upload/${IMG_DIR}"
mkdir -p "${PRODUCT_PATH}/${VERSION}"
# Move config.yaml file if exists.
if [ -f "${SRC_DIR}/config.yaml" ]; then
mv "${SRC_DIR}/config.yaml" "${PRODUCT_PATH}"
fi
# Move image content.
mv ${SRC_DIR}/* "${PRODUCT_PATH}/${VERSION}"
# s -> Uses SFTP protocol
# r -> Copies files recursively
# p -> Preserves modification and access times
scp -srp -P ${SSH_PORT} ${SRC_DIR}-upload/* "${SSH_USER}@${SSH_HOST}:."
10 changes: 8 additions & 2 deletions .github/workflows/image-almalinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build AlmaLinux Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image
workflow_call:
inputs:
publish:
type: boolean
default: true
description: Publish built image

jobs:
almalinux:
Expand Down Expand Up @@ -88,5 +93,6 @@ jobs:
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
image_dir: "${{ env.distro }}/${{ matrix.release }}/${{ matrix.architecture }}/${{ matrix.variant }}"
ssh_private_key: "${{ secrets.LXD_INFRA_IMAGES_KEY }}"
10 changes: 8 additions & 2 deletions .github/workflows/image-alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build Alpine Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image
workflow_call:
inputs:
publish:
type: boolean
default: true
description: Publish built image

jobs:
alpine:
Expand Down Expand Up @@ -90,5 +95,6 @@ jobs:
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
image_dir: "${{ env.distro }}/${{ matrix.release }}/${{ matrix.architecture }}/${{ matrix.variant }}"
ssh_private_key: "${{ secrets.LXD_INFRA_IMAGES_KEY }}"
10 changes: 8 additions & 2 deletions .github/workflows/image-alt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build ALT Linux Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image
workflow_call:
inputs:
publish:
type: boolean
default: true
description: Publish built image

jobs:
alt:
Expand Down Expand Up @@ -77,5 +82,6 @@ jobs:
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
image_dir: "${{ env.distro }}/${{ matrix.release }}/${{ matrix.architecture }}/${{ matrix.variant }}"
ssh_private_key: "${{ secrets.LXD_INFRA_IMAGES_KEY }}"
10 changes: 8 additions & 2 deletions .github/workflows/image-amazonlinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build AmazonLinux Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image
workflow_call:
inputs:
publish:
type: boolean
default: true
description: Publish built image

jobs:
amazonlinux:
Expand Down Expand Up @@ -103,5 +108,6 @@ jobs:
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
image_dir: "${{ env.distro }}/${{ matrix.release }}/${{ matrix.architecture }}/${{ matrix.variant }}"
ssh_private_key: "${{ secrets.LXD_INFRA_IMAGES_KEY }}"
10 changes: 8 additions & 2 deletions .github/workflows/image-archlinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build ArchLinux Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image
workflow_call:
inputs:
publish:
type: boolean
default: true
description: Publish built image

jobs:
archlinux:
Expand Down Expand Up @@ -97,5 +102,6 @@ jobs:
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
image_dir: "${{ env.distro }}/${{ matrix.release }}/${{ matrix.architecture }}/${{ matrix.variant }}"
ssh_private_key: "${{ secrets.LXD_INFRA_IMAGES_KEY }}"
10 changes: 8 additions & 2 deletions .github/workflows/image-busybox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build BusyBox Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image
workflow_call:
inputs:
publish:
type: boolean
default: true
description: Publish built image

jobs:
busybox:
Expand Down Expand Up @@ -73,5 +78,6 @@ jobs:
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
image_dir: "${{ env.distro }}/${{ matrix.release }}/${{ matrix.architecture }}/${{ matrix.variant }}"
ssh_private_key: "${{ secrets.LXD_INFRA_IMAGES_KEY }}"
10 changes: 8 additions & 2 deletions .github/workflows/image-centos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build CentOS Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image
workflow_call:
inputs:
publish:
type: boolean
default: true
description: Publish built image

jobs:
centos:
Expand Down Expand Up @@ -107,5 +112,6 @@ jobs:
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
image_dir: "${{ env.distro }}/${{ matrix.release }}/${{ matrix.architecture }}/${{ matrix.variant }}"
ssh_private_key: "${{ secrets.LXD_INFRA_IMAGES_KEY }}"
10 changes: 8 additions & 2 deletions .github/workflows/image-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build Debian Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image
workflow_call:
inputs:
publish:
type: boolean
default: true
description: Publish built image

jobs:
debian:
Expand Down Expand Up @@ -87,5 +92,6 @@ jobs:
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
image_dir: "${{ env.distro }}/${{ matrix.release }}/${{ matrix.architecture }}/${{ matrix.variant }}"
ssh_private_key: "${{ secrets.LXD_INFRA_IMAGES_KEY }}"
11 changes: 8 additions & 3 deletions .github/workflows/image-devuan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build Devuan Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image
workflow_call:
inputs:
publish:
type: boolean
default: true
description: Publish built image

jobs:
devuan:
Expand Down Expand Up @@ -77,6 +82,6 @@ jobs:
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
# types: ${{ env.type }}
image_dir: "${{ env.distro }}/${{ matrix.release }}/${{ matrix.architecture }}/${{ matrix.variant }}"
ssh_private_key: "${{ secrets.LXD_INFRA_IMAGES_KEY }}"
10 changes: 8 additions & 2 deletions .github/workflows/image-fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build Fedora Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image
workflow_call:
inputs:
publish:
type: boolean
default: true
description: Publish built image

jobs:
fedora:
Expand Down Expand Up @@ -88,5 +93,6 @@ jobs:
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
image_dir: "${{ env.distro }}/${{ matrix.release }}/${{ matrix.architecture }}/${{ matrix.variant }}"
ssh_private_key: "${{ secrets.LXD_INFRA_IMAGES_KEY }}"
10 changes: 8 additions & 2 deletions .github/workflows/image-funtoo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build Funtoo Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image
workflow_call:
inputs:
publish:
type: boolean
default: true
description: Publish built image

jobs:
funtoo:
Expand Down Expand Up @@ -78,5 +83,6 @@ jobs:
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
image_dir: "${{ env.distro }}/${{ matrix.release }}/${{ matrix.architecture }}/${{ matrix.variant }}"
ssh_private_key: "${{ secrets.LXD_INFRA_IMAGES_KEY }}"
Loading

0 comments on commit e13b5ed

Please sign in to comment.