Skip to content

Commit

Permalink
Optimize: Reduce Core image size & package removal
Browse files Browse the repository at this point in the history
Signed-off-by: Vipul Gupta (@vipulgupta2048) <[email protected]>
  • Loading branch information
vipulgupta2048 committed Jun 22, 2023
1 parent e1916ba commit 27f8e3d
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 259 deletions.
4 changes: 1 addition & 3 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
ARG BALENA_ARCH=%%BALENA_ARCH%%

FROM balenalib/armv7hf-alpine-node:16-run
FROM node:18.16.0-alpine3.16
WORKDIR /usr/src/app

# hadolint ignore=DL3018
Expand Down
19 changes: 7 additions & 12 deletions core/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
ARG BALENA_ARCH=%%BALENA_ARCH%%

FROM balenalib/armv7hf-node:16-bullseye as base
FROM node:16-bullseye-slim as base

WORKDIR /usr/app

Expand All @@ -12,16 +10,13 @@ ENV DEBIAN_FRONTEND noninteractive
# hadolint ignore=DL3008

RUN apt-get update && apt-get install --no-install-recommends -y \
bind9-dnsutils \
ca-certificates \
wget \
bind9-dnsutils \
docker.io \
git \
iproute2 \
jq \
openssh-client \
socat \
libudev-dev \
rsync \
libudev-dev \
unzip \
util-linux \
build-essential \
Expand All @@ -42,16 +37,16 @@ RUN if [ "$(uname -m)" = "arm64" ] || [ "$(uname -m)" = "aarch64" ] ; \
then \
npm i balena-cli@latest ; \
mkdir /usr/app/cli/ ; \
cp -R /usr/app/node_modules/balena-cli/ /usr/app ; \
mv /usr/app/node_modules/balena-cli/ /usr/app ; \
rm -rf /usr/app/node_modules/ ; \
else \
wget -q -O balena-cli.zip "https://github.com/balena-io/balena-cli/releases/download/${BALENA_CLI_REF}/balena-cli-v${BALENA_CLI_VERSION}-linux-x64-standalone.zip" && \
unzip balena-cli.zip && rm balena-cli.zip ; \
fi

# Add balena-cli to PATH
ENV PATH /usr/app/balena-cli:$PATH
RUN ls /usr/app/balena-cli && ls /usr/app/balena-cli/bin
ENV PATH $PATH:/usr/app/balena-cli/bin
# ENV PATH $PATH:/usr/app/balena-cli/bin

RUN balena version

Expand Down
62 changes: 0 additions & 62 deletions core/lib/common/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,62 +131,6 @@ module.exports = class Worker {
},
json: true,
});
// await new Promise(async (resolve, reject) => {
// const req = rp.post({
// uri: `${this.url}/dut/flash`,
// body: {
// path: imagePath
// },
// json: true
// });

// req.catch((error) => {
// reject(error);
// });
// req.finally(() => {
// if (lastStatus !== 'done') {
// reject(new Error('Unexpected end of TCP connection'));
// }

// resolve();
// });

// let lastStatus;
// req.on('data', (data) => {
// const computedLine = RegExp('(.+?): (.*)').exec(data.toString());

// if (computedLine) {
// if (computedLine[1] === 'error') {
// req.cancel();
// reject(new Error(computedLine[2]));
// }

// if (computedLine[1] === 'progress') {
// once(() => {
// this.logger.log('Flashing');
// });
// // Hide any errors as the lines we get can be half written
// const state = JSON.parse(computedLine[2]);
// if (state != null && isNumber(state.percentage)) {
// this.logger.status({
// message: 'Flashing',
// percentage: state.percentage,
// });
// }
// }

// if (computedLine[1] === 'status') {
// lastStatus = computedLine[2];
// }
// }
// });

// pipeline(
// fs.createReadStream(imagePath),
// createGzip({ level: 6 }),
// req,
// );
// });
this.logger.log('Flash completed');
},
{
Expand Down Expand Up @@ -431,12 +375,6 @@ module.exports = class Worker {
async executeCommandInWorker(command, retryOptions={}) {
return retry(
async () => {
// let containerId = await this.executeCommandInWorkerHost(
// `balena ps | grep worker | awk '{print $1}'`,
// );
// let result = await this.executeCommandInWorkerHost(
// `balena exec ${containerId} ${command}`,
// );
let result = await exec(command);
console.log(`Exec call: ${command}, Result: ${result}`)
return result;
Expand Down
6 changes: 3 additions & 3 deletions core/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = {
leviathan: {
artifacts: '/tmp/artifacts', // To store artifacts meant to be reported as results at the end of the suite
downloads: '/data/downloads', // To store/download assets needed for the suite (non-persistent)
downloads: '/data/workspace/downloads', // To store/download assets needed for the suite (non-persistent)
reports: '/reports/', // To store/download reports generated from the suite (non-persistent)
workdir: '/data',
uploads: {
config: '/data/workspace/config.js',
suite: '/data/suites'
config:'/data/config.json',
suite: '/data/suite'
}
}
};
61 changes: 0 additions & 61 deletions core/lib/main-standalone.js

This file was deleted.

38 changes: 19 additions & 19 deletions docker-compose.worker.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
version: "2"

services:
# client:
# build: ./client
# network_mode: host
# volumes:
# # - "${WORKSPACE:-./workspace}:/usr/src/app/workspace:ro"
# # - "${REPORTS:-./workspace/reports}:/usr/src/app/reports:rw"
# # - "${SUITES:-./suites}:/usr/src/app/suites:ro"
# - "${SUITES:-./suites}:/data/suites"
# - "${REPORTS:-./workspace/reports}:/data/reports"
# - "${WORKSPACE:-./workspace}:/data/workspace"
# environment:
# - WORKER_TYPE=${WORKER_TYPE}
# - DEVICE_TYPE=${DEVICE_TYPE}
# - BALENACLOUD_API_KEY=${BALENACLOUD_API_KEY}
# - BALENACLOUD_ORG=${BALENACLOUD_ORG}
# - BALENACLOUD_APP_NAME=${BALENACLOUD_APP_NAME}
# - CORE_HOST=localhost
# depends_on:
# - core
client:
build: ./client
network_mode: host
volumes:
# - "${WORKSPACE:-./workspace}:/usr/src/app/workspace:ro"
# - "${REPORTS:-./workspace/reports}:/usr/src/app/reports:rw"
# - "${SUITES:-./suites}:/usr/src/app/suites:ro"
- "${SUITES:-./suites}:/data/suites"
- "${REPORTS:-./workspace/reports}:/data/reports"
- "${WORKSPACE:-./workspace}:/data/workspace"
environment:
- WORKER_TYPE=${WORKER_TYPE}
- DEVICE_TYPE=${DEVICE_TYPE}
- BALENACLOUD_API_KEY=${BALENACLOUD_API_KEY}
- BALENACLOUD_ORG=${BALENACLOUD_ORG}
- BALENACLOUD_APP_NAME=${BALENACLOUD_APP_NAME}
- CORE_HOST=localhost
depends_on:
- core

core:
privileged: true # preload requires docker-in-docker
Expand Down
2 changes: 1 addition & 1 deletion suites/e2e/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module.exports = {
.sdk.fetchOS(
this.suite.options.balenaOS.download.version,
this.suite.deviceType.slug,
)}`
)}`
: undefined,
configJson: {
uuid: this.suite.options.balenaOS.config.uuid,
Expand Down
1 change: 0 additions & 1 deletion suites/e2e/tests/flash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = {
run: async function (test) {
try {
await this.worker.off(); // Ensure DUT is off before starting tests
console.log(`suite image path: ${this.os.image.path}`)
await this.worker.flash(this.os.image.path);
} catch (err) {
throw new Error(`Flashing failed with error: ${err}`);
Expand Down
6 changes: 3 additions & 3 deletions testrunner/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# avoid alpine 3.13 or later due to this issue on armv7
# https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.13.0#time64_requirements
FROM alpine:3.12

FROM balenalib/armv7hf-alpine:3.15-run

WORKDIR /usr/src/app

# https://github.com/balena-io/balena-cli/blob/master/INSTALL-LINUX.md#additional-dependencies
# hadolint ignore=DL3018
RUN apk add --no-cache bash git ca-certificates docker nano make curl
RUN apk add --no-cache git ca-certificates docker nano make curl

# fail if binaries are missing or won't run
RUN dockerd --version && docker --version
Expand Down
94 changes: 0 additions & 94 deletions testrunner/config.js

This file was deleted.

3 changes: 3 additions & 0 deletions testrunner/entry.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# Clone Leviathan
https://github.com/balena-os/Leviathan

rm -rf /var/run/docker 2>/dev/null || true
rm -f /var/run/docker.sock 2>/dev/null || true
rm -f /var/run/docker.pid 2>/dev/null || true
Expand Down

0 comments on commit 27f8e3d

Please sign in to comment.