feat: try to quicken builds by using docker and sharing image

This commit is contained in:
Eli Bosley
2023-08-30 16:33:08 -04:00
parent 61c162dc1e
commit 6c0aea6dd2
9 changed files with 97 additions and 109 deletions
+55 -65
View File
@@ -11,68 +11,71 @@ concurrency:
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
persist-credentials: true
- name: Reconfigure git to use HTTP authenti:cation
run: >
git config --global url."https://github.com/".insteadOf
ssh://git@github.com/
- name: Build Docker Compose
working-directory: api
run: |
docker-compose build builder
- name: Save Image
run: docker save unraid-api:builder > /tmp/builder.tar
- name: Upload Image
uses: actions/upload-artifact@v3
with:
name: builder
path: /tmp/builder.tar
lint-api:
needs: [build]
continue-on-error: true
defaults:
run:
working-directory: api
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
persist-credentials: false
- name: Reconfigure git to use HTTP authenti:cation
run: >
git config --global url."https://github.com/".insteadOf
ssh://git@github.com/
- name: Install node
uses: actions/setup-node@v3
with:
node-version-file: "api/.nvmrc"
# - name: Cache dependencies
# uses: actions/cache@v2
# with:
# path: ~/.npm
# key: npm-${{ hashFiles('package-lock.json') }}
# restore-keys: npm-
- name: Install libvirt-dev
run: sudo apt-get update && sudo apt-get install libvirt-dev
- name: Installing node deps
run: npm ci
- name: Lint files
run: npm run lint
name: builder
path: /tmp
- name: Load image
run: |
docker load --input /tmp/builder.tar
- name: Lint
run: |
docker run unraid-api:builder npm run lint
test-api:
needs: [build]
defaults:
run:
working-directory: api
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
persist-credentials: false
- name: Reconfigure git to use HTTP authentication
run: >
git config --global url."https://github.com/".insteadOf
ssh://git@github.com/
- name: Build Docker Compose
name: builder
path: /tmp
- name: Load image
run: |
docker network create mothership_default
docker-compose build builder
- name: Run Docker Compose
run: docker-compose run builder npm run coverage
docker load --input /tmp/builder.tar
- name: Test
run: |
docker run unraid-api:builder npm run coverage
build-api:
needs: [build]
defaults:
run:
working-directory: api
@@ -87,30 +90,17 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v3
- name: Install node
uses: actions/setup-node@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
node-version-file: "api/.nvmrc"
name: build
path: /tmp
- name: Load image
run: |
docker load --input /tmp/builder.tar
- name: Install libvirt-dev
run: sudo apt-get update && sudo apt-get install libvirt-dev
# - name: Cache dependencies
# uses: actions/cache@v2
# with:
# path: ~/.npm
# key: npm-${{ hashFiles('package-lock.json') }}
# restore-keys: npm-
- name: Installing node deps
run: npm install
- name: Install pkg
run: npm i -g pkg
- name: Build and Pack
id: build-pack-binary
run: WORKDIR=${{ github.workspace }} && npm run build-pkg
- name: Run Docker Compose
run: docker run builder npm run build-pkg
- name: Set Hashes
id: set-hashes
+13 -4
View File
@@ -1,11 +1,13 @@
###########################################################
# Development/Build Image
###########################################################
ARG NODE_IMAGE=node:18.17.1
ARG NODE_IMAGE=node:18.17.1-alpine
FROM $NODE_IMAGE As development
# Install build tools
RUN apt-get update -y && apt-get install -y \
# Install build tools and dependencies
RUN apk update && apk add \
bash \
alpine-sdk \
python3 \
libvirt-dev \
jq \
@@ -13,7 +15,6 @@ RUN apt-get update -y && apt-get install -y \
RUN mkdir /var/log/unraid-api/
ARG NODE_ENV=development
ARG NPM_I_CMD=npm i
@@ -39,4 +40,12 @@ RUN npm i -g pkg zx
EXPOSE 4000
###########################################################
# Builder Image
###########################################################
FROM development AS builder
COPY ./src ./src
CMD ["npm", "run", "build-pkg"]
+1 -1
View File
@@ -1,5 +1,5 @@
[api]
version="3.1.1+251f9020"
version="3.1.1+8efc0992"
[local]
[notifier]
apikey="unnotify_30994bfaccf839c65bae75f7fa12dd5ee16e69389f754c3b98ed7d5"
+1 -1
View File
@@ -1,5 +1,5 @@
[api]
version="3.1.1+251f9020"
version="3.1.1+8efc0992"
[local]
[notifier]
apikey="unnotify_30994bfaccf839c65bae75f7fa12dd5ee16e69389f754c3b98ed7d5"
+6 -6
View File
@@ -27,20 +27,20 @@ x-volumes: &volumes
networks:
mothership_default:
external: true
services:
dev:
networks:
- mothership_default
image: unraid-api-node-18
image: unraid-api:development
ports:
- "3001:3001"
build:
context: .
target: development
dockerfile: Dockerfile
args:
NODE_IMAGE: node:18.17.1
NODE_IMAGE: node:18.17.1-alpine
NODE_ENV: development
NPM_I_CMD: npm i
<<: *volumes
@@ -54,15 +54,15 @@ services:
builder:
image: unraid-api-node-18
image: unraid-api:builder
build:
context: .
target: builder
dockerfile: Dockerfile
args:
NODE_IMAGE: node:18.17.1
NODE_IMAGE: node:18.17.1-alpine
NODE_ENV: development
NPM_I_CMD: npm i
<<: *volumes
platform: linux/amd64
profiles:
- builder
+10 -21
View File
@@ -63,7 +63,6 @@
"pidusage": "^3.0.2",
"reflect-metadata": "^0.1.13",
"request": "^2.88.2",
"segfault-handler": "^1.3.0",
"semver": "^7.4.0",
"stoppable": "^1.1.0",
"subscriptions-transport-ws": "^0.11.0",
@@ -4317,6 +4316,7 @@
"node_modules/bindings": {
"version": "1.5.0",
"license": "MIT",
"optional": true,
"dependencies": {
"file-uri-to-path": "1.0.0"
}
@@ -7452,7 +7452,8 @@
},
"node_modules/file-uri-to-path": {
"version": "1.0.0",
"license": "MIT"
"license": "MIT",
"optional": true
},
"node_modules/fill-range": {
"version": "7.0.1",
@@ -10705,7 +10706,8 @@
},
"node_modules/nan": {
"version": "2.17.0",
"license": "MIT"
"license": "MIT",
"optional": true
},
"node_modules/nanoassert": {
"version": "1.1.0",
@@ -12852,15 +12854,6 @@
"dev": true,
"license": "MIT"
},
"node_modules/segfault-handler": {
"version": "1.3.0",
"hasInstallScript": true,
"license": "BSD-3-Clause",
"dependencies": {
"bindings": "^1.2.1",
"nan": "^2.14.0"
}
},
"node_modules/semver": {
"version": "7.5.4",
"license": "ISC",
@@ -18273,6 +18266,7 @@
},
"bindings": {
"version": "1.5.0",
"optional": true,
"requires": {
"file-uri-to-path": "1.0.0"
}
@@ -20298,7 +20292,8 @@
}
},
"file-uri-to-path": {
"version": "1.0.0"
"version": "1.0.0",
"optional": true
},
"fill-range": {
"version": "7.0.1",
@@ -22331,7 +22326,8 @@
}
},
"nan": {
"version": "2.17.0"
"version": "2.17.0",
"optional": true
},
"nanoassert": {
"version": "1.1.0"
@@ -23626,13 +23622,6 @@
"version": "1.1.0",
"dev": true
},
"segfault-handler": {
"version": "1.3.0",
"requires": {
"bindings": "^1.2.1",
"nan": "^2.14.0"
}
},
"semver": {
"version": "7.5.4",
"requires": {
-2
View File
@@ -13,7 +13,6 @@
"pkg": {
"assets": [
"dist/index.cjs",
"node_modules/segfault-handler",
"node_modules/@vmngr/libvirt/build/Release",
"node_modules/ts-invariant/",
"src/**/*.graphql"
@@ -112,7 +111,6 @@
"pidusage": "^3.0.2",
"reflect-metadata": "^0.1.13",
"request": "^2.88.2",
"segfault-handler": "^1.3.0",
"semver": "^7.4.0",
"stoppable": "^1.1.0",
"subscriptions-transport-ws": "^0.11.0",
+11
View File
@@ -0,0 +1,11 @@
import 'wtfnode';
import { am } from 'am';
import { main } from '@app/cli/index';
import { internalLogger } from '@app/core/log';
void am(main, (error: unknown) => {
internalLogger.fatal((error as Error).message);
// Ensure process is exited
process.exit(1);
});
-9
View File
@@ -1,4 +1,3 @@
import { causeSegfault } from 'segfault-handler';
import { parse } from 'ts-command-line-args';
import { cliLogger } from '@app/core/log';
import { type Flags, mainOptions, options, args } from '@app/cli/options';
@@ -64,14 +63,6 @@ export const main = async (...argv: string[]) => {
// Run the command
await commandMethod(...argv);
// Only segfault in a specific mode
if (process.env.PLEASE_SEGFAULT_FOR_ME) {
// Wait 30s and then segfault
setTimeout(() => {
causeSegfault();
}, 30_000);
}
// Allow the process to exit
// Don't exit when we start though
if (!['start', 'restart'].includes(command)) {