Skip to content

Commit

Permalink
Merge pull request #8 from dimikot/grok/dimikot/add-publishing-to-doc…
Browse files Browse the repository at this point in the history
…kerhub-to-main-b401

Add publishing to DockerHub
  • Loading branch information
dimikot authored Mar 2, 2024
2 parents 503058b + 32723de commit 2546714
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 27 deletions.
88 changes: 67 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ on:
push:
branches:
- main
tags:
- "v*"

jobs:
# Tests ci-storage tool itself.
ci-storage-test:
ci-storage-tool-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Create dummy file
run: |
echo "dummy" > dummy.txt
Expand All @@ -38,41 +39,36 @@ jobs:
# Builds and boots a self-hosted runner inside GitHub's infra. Once it's
# settled, there is a running container with one self-hosted runner waiting
# for jobs with "ci-storage-test" tag to pick up (based on Dockerfile image).
self-hosted-runner-build-and-boot-docker-container:
build-and-boot-containers:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
actions: write
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Start test Docker containers
run: |
exec 2>&1; set -o xtrace
exec 2>&1; set -e -o xtrace
cd docker
# Build all containers.
docker compose build --parallel
# Boot ci-storage-host container in background.
docker compose up ci-storage-host -d
# Now boot self-hosted-runner container. It will connect to
# ci-storage-host container and load a test (non-existent) ci-storage
# slot from there, then register a GitHub self-hosted runner and
# remain waiting for jobs.
# Boot "host" container in background.
docker compose up host -d
# Boot "self-hosted-runner" container. It connects to "host" container
# and load a test (non-existent) ci-storage slot from there, then
# register a GitHub self-hosted runner and remain waiting for jobs.
docker compose up self-hosted-runner
env:
GH_REPOSITORY: ${{ github.repository }}
GH_LABELS: ci-storage-test
GH_TOKEN: ${{ secrets.CI_PAT }}

# The test job with ci-storage-test tag which is initially queued, but then is
# picked up by the self-hosted-runner container booted in the previous job. In
# the end, the test job sends SIGINT to the container entrypoint.sh PID, so
# Test the job with "ci-storage-test" tag which is initially queued, but then
# is picked up by the self-hosted-runner container booted in the previous job.
# In the end, the test job sends SIGINT to the container entrypoint.sh PID, so
# the container (based on Dockerfile image) shuts down gracefully.
self-hosted-runner-spawn-job-test:
spawn-job-test:
runs-on: ["self-hosted", "ci-storage-test"]
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Run test job inside the self-hosted runner
run: echo "Hello, world!"
- name: Test store using GitHub Action
Expand All @@ -81,3 +77,53 @@ jobs:
action: "store"
- name: Kill self-hosted runner container
run: kill -SIGINT $(cat ~user/entrypoint.pid)

# Publishes host image to Docker Hub.
push-host:
runs-on: ubuntu-latest
needs:
- ci-storage-tool-test
- build-and-boot-containers
- spawn-job-test
steps:
- uses: actions/checkout@v4
- 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
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# Publishes self-hosted-runner image to Docker Hub.
push-self-hosted-runner:
runs-on: ubuntu-latest
needs:
- ci-storage-tool-test
- build-and-boot-containers
- spawn-job-test
steps:
- uses: actions/checkout@v4
- 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
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
8 changes: 4 additions & 4 deletions docker/compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: "3.4"
services:
ci-storage-host:
host:
build:
context: ci-storage-host
context: host
dockerfile: Dockerfile
healthcheck:
test: ["CMD", "bash", "-c", "netstat -ltn | grep -c :22"]
Expand All @@ -18,11 +18,11 @@ services:
context: self-hosted-runner
dockerfile: Dockerfile
depends_on:
ci-storage-host:
host:
condition: service_healthy
environment:
- GH_REPOSITORY=${GH_REPOSITORY:-dimikot/ci-storage}
- GH_LABELS=${GH_LABELS:-ci-storage}
- GH_TOKEN
- CI_STORAGE_HOST=${CI_STORAGE_HOST:-ci-storage-host}
- CI_STORAGE_HOST=${CI_STORAGE_HOST:-host}
- CI_STORAGE_HOST_PRIVATE_KEY=${CI_STORAGE_HOST_PRIVATE_KEY_TEST_ONLY?}
File renamed without changes.
4 changes: 2 additions & 2 deletions docker/ci-storage-host/README.md → docker/host/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Build an image from this Dockerfile to launch a simple SSH server with rsync.
- Pre-creates /home/user/ci-storage directory.
- Copies public key in CI_STORAGE_HOST_PUBLIC_KEY to user's authorized_keys.

One ci-storage-host contain may serve multiple GitHub repositories. Each of them
will have own directory in /home/user/ci-storage (managed by ci-storage tool).
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).
File renamed without changes.

0 comments on commit 2546714

Please sign in to comment.