Skip to content

Commit

Permalink
ci: start Docker image and test output (#110)
Browse files Browse the repository at this point in the history
- Fix Dockerfile to accommodate the latest changes and build a working
  Docker image again.

- Upgrade Saturn L2 Node to version v0.5.1
  https://github.com/filecoin-saturn/L2-node/releases/tag/v0.5.1

- Add a new section to our CI workflow to build the Docker image, run it
  and check the activity log to verify that all modules have started.

- Partially revert 6bbd34c. The "Docker" workflow is executed for
  release builds only; the pull requests are tested using the newly
  added section in the "CI" workflow.

Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos authored Apr 26, 2023
1 parent 94801cf commit 1086593
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 14 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
modules
npm-debug.log
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,65 @@ jobs:
- run: npm run test:lint
if: matrix.os != 'windows-latest'
- run: npm run test:unit

docker:
name: Build and test Docker
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
env:
REGISTRY: ghcr.io

steps:
- uses: actions/checkout@v3

- uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: "arm64"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and load Docker image
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
load: true
tags: core-test
cache-from: type=registry,ref=ghcr.io/filecoin-station/core
cache-to: type=inline

- name: Build Docker image for other platforms
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/arm64
cache-from: type=registry,ref=ghcr.io/filecoin-station/core
cache-to: type=inline

- name: Start Station Core container
run: |
docker run \
--name station \
--detach \
--env FIL_WALLET_ADDRESS=f1abjxfbp274xpdqcpuaykwkfb43omjotacm2p3za \
$IMAGEID
env:
IMAGEID: ${{ steps.docker_build.outputs.imageid }}

- name: Print station activity
run: |
sleep 10 # Wait for Station modules to start
docker exec station bin/station.js activity
- name: Check | Saturn started
run: docker exec station bin/station.js activity | grep "Saturn module started"
5 changes: 2 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Docker build
on:
push:
tags: ["*"]
branches: ["*"]

env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -35,11 +34,11 @@ jobs:
- uses: martinbeentjes/npm-get-version-action@main
id: package-version

- name: Build and optionally push Docker image
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
push: true
tags: |
ghcr.io/filecoin-station/core
ghcr.io/filecoin-station/core:${{ steps.package-version.outputs.current-version }}
Expand Down
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ FROM node:18-alpine
LABEL org.opencontainers.image.source https://github.com/filecoin-station/core
USER node
WORKDIR /usr/src/app
COPY package*.json ./
COPY scripts/post-install.js ./scripts/
RUN npm ci --omit=dev
COPY . .
RUN npm ci --omit=dev
CMD [ "./bin/station.js" ]
2 changes: 1 addition & 1 deletion bin/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ yargs(hideBin(process.argv))
commands.activity
)
.command('logs [module]', 'Show module logs', () => {}, commands.logs)
.choices('module', ['saturn-l2-node'])
.choices('module', modules)
.version(`${pkg.name}: ${pkg.version}`)
.alias('v', 'version')
.alias('h', 'help')
Expand Down
10 changes: 5 additions & 5 deletions lib/saturn-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { fetch } from 'undici'
import * as Sentry from '@sentry/node'
import { installBinaryModule, getBinaryModuleExecutable } from './modules.js'

const DIST_TAG = 'v0.5.0'
const DIST_TAG = 'v0.5.1'

export async function install () {
await installBinaryModule({
module: 'saturn-l2-node',
module: 'saturn-L2-node',
repo: 'filecoin-saturn/L2-node',
distTag: DIST_TAG,
executable: 'L2-node',
executable: 'saturn-L2-node',
arch: platform() === 'darwin' ? 'x64' : arch(),
targets: [
{ platform: 'darwin', arch: 'x64', asset: 'L2-node_Darwin_x86_64.zip' },
Expand All @@ -36,8 +36,8 @@ async function start ({

const childProcess = execa(
getBinaryModuleExecutable({
module: 'saturn-l2-node',
executable: 'L2-node'
module: 'saturn-L2-node',
executable: 'saturn-L2-node'
}), {
env: {
ROOT_DIR: storagePath,
Expand Down
4 changes: 2 additions & 2 deletions test/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ describe('Metrics', () => {
{ recursive: true }
)
await fs.writeFile(
join(getPaths(CACHE_ROOT, STATE_ROOT).metrics, 'saturn-l2-node.log'),
join(getPaths(CACHE_ROOT, STATE_ROOT).metrics, 'saturn-L2-node.log'),
'[date] {"totalJobsCompleted":1,"totalEarnings":"2"}\n'
)
const { stdout } = await execa(
station,
['metrics', 'saturn-l2-node'],
['metrics', 'saturn-L2-node'],
{ env: { CACHE_ROOT, STATE_ROOT } }
)
assert.deepStrictEqual(
Expand Down

0 comments on commit 1086593

Please sign in to comment.