Skip to content

Commit

Permalink
Avoid the need to specify each image individually in load-img (#1855)
Browse files Browse the repository at this point in the history
Co-authored-by: Olga Bulat <obulat@gmail.com>
  • Loading branch information
dhruvkb and obulat committed Apr 24, 2023
1 parent f5c6c7a commit 1b34383
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 85 deletions.
100 changes: 25 additions & 75 deletions .github/actions/load-img/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,41 @@ description: Download and import Docker images from artifacts

inputs:
setup_images:
default: '["upstream_db", "ingestion_server", "catalog", "api", "api_nginx", "frontend"]'
description: JSON-encoded list of image names
default: "upstream_db ingestion_server catalog api api_nginx frontend"
description: Space-separated list of image names

runs:
using: "composite"
steps:
# Upstream DB
- name: Download image `upstream_db`
uses: actions/download-artifact@v3
if: contains(fromJson(inputs.setup_images), 'upstream_db')
with:
name: upstream_db
path: /tmp

- name: Load image `upstream_db`
if: contains(fromJson(inputs.setup_images), 'upstream_db')
shell: bash
run: |
docker load --input /tmp/upstream_db.tar
# Catalog
- name: Download image `catalog`
uses: actions/download-artifact@v3
if: contains(fromJson(inputs.setup_images), 'catalog')
with:
name: catalog
path: /tmp

- name: Load image `catalog`
if: contains(fromJson(inputs.setup_images), 'catalog')
shell: bash
run: |
docker load --input /tmp/catalog.tar
# Ingestion server
- name: Download image `ingestion_server`
uses: actions/download-artifact@v3
if: contains(fromJson(inputs.setup_images), 'ingestion_server')
with:
name: ingestion_server
path: /tmp

- name: Load image `ingestion_server`
if: contains(fromJson(inputs.setup_images), 'ingestion_server')
shell: bash
run: |
docker load --input /tmp/ingestion_server.tar
# API
- name: Download image `api`
uses: actions/download-artifact@v3
if: contains(fromJson(inputs.setup_images), 'api')
with:
name: api
path: /tmp
- name: Checkout repository
uses: actions/checkout@v3

- name: Load image `api`
if: contains(fromJson(inputs.setup_images), 'api')
shell: bash
run: |
docker load --input /tmp/api.tar
- name: Download image `api_nginx`
uses: actions/download-artifact@v3
if: contains(fromJson(inputs.setup_images), 'api_nginx')
# Doesn't use `setup-env` because the next step uses `npm`, not `pnpm`.
- name: Setup Node.js
uses: actions/setup-node@v3
with:
name: api_nginx
path: /tmp
node-version: "16"

- name: Load image `api_nginx`
if: contains(fromJson(inputs.setup_images), 'api_nginx')
- name: Install `@actions/artifact`
shell: bash
run: |
docker load --input /tmp/api_nginx.tar
npm install @actions/artifact
# Frontend
- name: Download image `frontend`
uses: actions/download-artifact@v3
if: contains(fromJson(inputs.setup_images), 'frontend')
- name: Download images
uses: actions/github-script@v6
with:
name: frontend
path: /tmp

- name: Load image `frontend`
if: contains(fromJson(inputs.setup_images), 'frontend')
script: |
const artifact = require("@actions/artifact")
const artifactClient = artifact.create()
const images = "${{ inputs.setup_images }}".split(" ")
for (image of images) {
await artifactClient.downloadArtifact(image, "/tmp", { createArtifactFolder: false })
}
- name: Load images
shell: bash
run: |
docker load --input /tmp/frontend.tar
images=(${{ inputs.setup_images }});
for image in "${images[@]}"; do
docker load --input /tmp/${image}.tar
done
12 changes: 6 additions & 6 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ jobs:
- name: Load Docker images
uses: ./.github/actions/load-img
with:
setup_images: '["upstream_db", "catalog"]'
setup_images: upstream_db catalog

- name: Run tests
run: |
Expand Down Expand Up @@ -281,7 +281,7 @@ jobs:
- name: Load Docker images
uses: ./.github/actions/load-img
with:
setup_images: '["upstream_db", "catalog"]'
setup_images: upstream_db catalog

- name: Check DAG documentation
run: |
Expand Down Expand Up @@ -315,7 +315,7 @@ jobs:
- name: Load Docker images
uses: ./.github/actions/load-img
with:
setup_images: '["upstream_db", "ingestion_server"]'
setup_images: upstream_db ingestion_server

- name: Run ingestion-server tests
run: just ingestion_server/test-local
Expand Down Expand Up @@ -360,7 +360,7 @@ jobs:
- name: Load Docker images
uses: ./.github/actions/load-img
with:
setup_images: '["upstream_db", "ingestion_server", "api"]'
setup_images: upstream_db ingestion_server api

- name: Start API, ingest and index test data
run: just api/init
Expand Down Expand Up @@ -413,7 +413,7 @@ jobs:
- name: Load Docker images
uses: ./.github/actions/load-img
with:
setup_images: '["upstream_db", "ingestion_server", "api"]'
setup_images: upstream_db ingestion_server api

- name: Run check recipe
run: just ${{ matrix.recipe }}
Expand Down Expand Up @@ -798,7 +798,7 @@ jobs:
- name: Load Docker image `${{ matrix.image }}`
uses: ./.github/actions/load-img
with:
setup_images: ${{ format('["{0}"]', matrix.image) }}
setup_images: ${{ matrix.image }}

- name: Load and tag image `${{ matrix.image }}` (latest & sha)
run: |
Expand Down
8 changes: 4 additions & 4 deletions documentation/meta/ci_cd/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ downloads the artifact and load the `.tar` files into Docker as images.

**Inputs:**

By default, all images built by the Docker system will be loaded but if the job
only needs a subset of images, those can be set via the `setup_images` input,
passing a JSON encoded array of image names as strings.
By default, all images built by the Docker system will be loaded. However, if
the job only needs a subset of images, those can be set via the `setup_images`
input, passing a space-separated list of image names.

```typescript
{
setup_images: string // default: '["upstream_db", "ingestion_server", "catalog", "api", "api_nginx", "frontend"]'
setup_images: string // default: 'upstream_db ingestion_server catalog api api_nginx frontend'
}
```

Expand Down

0 comments on commit 1b34383

Please sign in to comment.