From cb523b591de6fb51fcd171a8c18409de737111da Mon Sep 17 00:00:00 2001 From: Dimi Kot Date: Sat, 2 Mar 2024 04:09:36 -0800 Subject: [PATCH] Publish for all platforms Pull Request: https://github.com/dimikot/ci-storage/pull/9 (main) --- .github/workflows/ci.yml | 32 ++++++++++++++++++++----- docker/host/README.md | 2 ++ docker/host/entrypoint.sh | 2 +- docker/self-hosted-runner/README.md | 2 ++ docker/self-hosted-runner/entrypoint.sh | 22 +++++++++-------- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c58927e..3f3c520 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: docker compose up self-hosted-runner env: GH_REPOSITORY: ${{ github.repository }} - GH_LABELS: ci-storage-test + GH_LABELS: ${{ format('ci-storage-test-{0}-{1}', github.run_id, github.run_attempt) }} GH_TOKEN: ${{ secrets.CI_PAT }} # Test the job with "ci-storage-test" tag which is initially queued, but then @@ -66,7 +66,9 @@ jobs: # In the end, the test job sends SIGINT to the container entrypoint.sh PID, so # the container (based on Dockerfile image) shuts down gracefully. spawn-job-test: - runs-on: ["self-hosted", "ci-storage-test"] + runs-on: + - self-hosted + - ${{ format('ci-storage-test-{0}-{1}', github.run_id, github.run_attempt) }} steps: - uses: actions/checkout@v4 - name: Run test job inside the self-hosted runner @@ -78,52 +80,70 @@ jobs: - name: Kill self-hosted runner container run: kill -SIGINT $(cat ~user/entrypoint.pid) - # Publishes host image to Docker Hub. + # Publishes "host" image to Docker Hub. push-host: runs-on: ubuntu-latest + if: github.event_name != 'pull_request' needs: - ci-storage-tool-test - build-and-boot-containers - spawn-job-test steps: - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 - uses: docker/metadata-action@v5 id: meta with: images: dimikot/ci-storage-host - uses: docker/login-action@v3 - if: github.event_name != 'pull_request' with: username: dimikot password: ${{ secrets.DOCKERHUB_PAT }} - uses: docker/build-push-action@v5 with: context: docker/host + platforms: linux/amd64,linux/arm64,linux/arm64/v8 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + - uses: peter-evans/dockerhub-description@v3 + with: + username: dimikot + password: ${{ secrets.DOCKERHUB_PAT }} + readme-filepath: docker/host/README.md + repository: dimikot/ci-storage-host - # Publishes self-hosted-runner image to Docker Hub. + # Publishes "self-hosted-runner" image to Docker Hub. push-self-hosted-runner: runs-on: ubuntu-latest + if: github.event_name != 'pull_request' needs: - ci-storage-tool-test - build-and-boot-containers - spawn-job-test steps: - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 - uses: docker/metadata-action@v5 id: meta with: images: dimikot/ci-storage-self-hosted-runner - uses: docker/login-action@v3 - if: github.event_name != 'pull_request' with: username: dimikot password: ${{ secrets.DOCKERHUB_PAT }} - uses: docker/build-push-action@v5 with: context: docker/self-hosted-runner + platforms: linux/amd64,linux/arm64,linux/arm64/v8 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + - uses: peter-evans/dockerhub-description@v3 + with: + username: dimikot + password: ${{ secrets.DOCKERHUB_PAT }} + readme-filepath: docker/self-hosted-runner/README.md + repository: dimikot/ci-storage-self-hosted-runner diff --git a/docker/host/README.md b/docker/host/README.md index ea6e51f..11e0add 100644 --- a/docker/host/README.md +++ b/docker/host/README.md @@ -7,3 +7,5 @@ Build an image from this Dockerfile to launch a simple SSH server with rsync. One "host" container may serve multiple GitHub repositories. Each of them will have own directory in /home/user/ci-storage (managed by ci-storage tool). + +See also https://github.com/dimikot/ci-storage diff --git a/docker/host/entrypoint.sh b/docker/host/entrypoint.sh index 11f7cec..0d3cf55 100644 --- a/docker/host/entrypoint.sh +++ b/docker/host/entrypoint.sh @@ -5,7 +5,7 @@ # set -u -e -if [[ "${CI_STORAGE_HOST_PUBLIC_KEY:=''}" == "" ]]; then +if [[ "${CI_STORAGE_HOST_PUBLIC_KEY:=}" == "" ]]; then echo "CI_STORAGE_HOST_PUBLIC_KEY must be set to a valid SSH public key." exit 1 fi diff --git a/docker/self-hosted-runner/README.md b/docker/self-hosted-runner/README.md index 8830ed4..6ed5c8b 100644 --- a/docker/self-hosted-runner/README.md +++ b/docker/self-hosted-runner/README.md @@ -24,3 +24,5 @@ self-hosted runners as you want. An example scenario: The container in this Dockerfile is serves only one particular GitHub repository (controlled by GH_REPOSITORY environment variable at boot time). To serve different repositories, boot different containers. + +See also https://github.com/dimikot/ci-storage diff --git a/docker/self-hosted-runner/entrypoint.sh b/docker/self-hosted-runner/entrypoint.sh index 87a4024..806252c 100644 --- a/docker/self-hosted-runner/entrypoint.sh +++ b/docker/self-hosted-runner/entrypoint.sh @@ -17,23 +17,23 @@ # set -u -e -if [[ "${GH_REPOSITORY:=''}" != */* ]]; then +if [[ "${GH_REPOSITORY:=}" != */* ]]; then echo "GH_REPOSITORY must be set, and the format should be {owner}/{repo}."; exit 1; fi -if [[ "${GH_LABELS:=''}" == "" ]]; then +if [[ "${GH_LABELS:=}" == "" ]]; then echo "GH_LABELS must be set."; exit 1; fi -if [[ "${GH_TOKEN:=''}" == "" ]]; then +if [[ "${GH_TOKEN:=}" == "" ]]; then echo "GH_TOKEN must be set."; exit 1; fi -if [[ "${CI_STORAGE_HOST:=''}" != "" && ! "$CI_STORAGE_HOST" =~ ^([-.[:alnum:]]+@)?[-.[:alnum:]]+$ ]]; then +if [[ "${CI_STORAGE_HOST:=}" != "" && ! "$CI_STORAGE_HOST" =~ ^([-.[:alnum:]]+@)?[-.[:alnum:]]+$ ]]; then echo "If CI_STORAGE_HOST is passed, it must be in form of {hostname} or {user}@{hostname}."; exit 1; fi -if [[ "${CI_STORAGE_HOST_PRIVATE_KEY:=''}" != "" && "$CI_STORAGE_HOST_PRIVATE_KEY" != *OPENSSH\ PRIVATE\ KEY* ]]; then +if [[ "${CI_STORAGE_HOST_PRIVATE_KEY:=}" != "" && "$CI_STORAGE_HOST_PRIVATE_KEY" != *OPENSSH\ PRIVATE\ KEY* ]]; then echo "If CI_STORAGE_HOST_PRIVATE_KEY is passed, it must be an SSH private key."; exit 1; fi @@ -60,11 +60,13 @@ if [[ "$CI_STORAGE_HOST" != "" ]]; then ssh-keyscan -H "$CI_STORAGE_HOST" >> ~/.ssh/known_hosts chmod 600 ~/.ssh/known_hosts mkdir -p "$local_dir" - ci-storage load \ - --storage-host="$CI_STORAGE_HOST" \ - --storage-dir="~/ci-storage/$GH_REPOSITORY" \ - --slot-id="?" \ - --local-dir="$local_dir" + if [[ "$CI_STORAGE_HOST_PRIVATE_KEY" != "" ]]; then + ci-storage load \ + --storage-host="$CI_STORAGE_HOST" \ + --storage-dir="~/ci-storage/$GH_REPOSITORY" \ + --slot-id="?" \ + --local-dir="$local_dir" + fi fi token=$(gh api -X POST --jq .token "repos/$GH_REPOSITORY/actions/runners/registration-token")