Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build UI during package instead of install #621

Merged
merged 31 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3ecaad1
Build UI during package
jboddey Jul 22, 2024
caf9476
Fix local build
jboddey Jul 22, 2024
17f30c6
Install npm
jboddey Jul 22, 2024
784d1a3
Remove duplicate build message
jboddey Jul 22, 2024
ff16719
Fix ESLint
sofyakurilova Jul 22, 2024
42cf14e
Fix script
jboddey Jul 22, 2024
e9c1c2b
Merge branch 'feature/ui_build' of /~https://github.com/google/testrun …
jboddey Jul 22, 2024
95b988c
Modify scripts
jboddey Jul 22, 2024
066750f
Improve scripts
jboddey Jul 22, 2024
877b6ec
Fix copy command
jboddey Jul 22, 2024
106a43f
Try installing package
jboddey Jul 22, 2024
9fb8063
Depend on package job
jboddey Jul 22, 2024
d6f3bc6
Add sudo
jboddey Jul 22, 2024
8b745f3
Add sudo
jboddey Jul 22, 2024
41cf179
Troubleshoot
jboddey Jul 23, 2024
b78eec7
Fix workflow
jboddey Jul 23, 2024
725ee58
Checkout source for prepare command
jboddey Jul 23, 2024
21b3861
Merge branch 'dev' into feature/ui_build
jboddey Jul 24, 2024
48ecbe1
Merge branch 'dev' into feature/ui_build
jboddey Jul 25, 2024
ae17556
Built ui within a container
jboddey Jul 25, 2024
c4e4e63
Merge branch 'dev' into feature/ui_build
jboddey Jul 25, 2024
e64f4a7
Merge branch 'dev' into feature/ui_build
jboddey Jul 30, 2024
27332d1
Mount src files for build instead of static copy in build image
jhughesbiot Jul 30, 2024
1225a87
Merge branch 'dev' into feature/ui_build
jhughesbiot Jul 30, 2024
e009e9e
Attempt to fix actions
jhughesbiot Jul 30, 2024
b596780
Remove manual build container cleanup methods
jhughesbiot Jul 30, 2024
349fb4a
undo failed attempts to fix actions
jhughesbiot Jul 30, 2024
2096751
Fix path
jhughesbiot Jul 30, 2024
27f6fd0
Remove -it flag
jboddey Jul 31, 2024
21686a3
Merge branch 'dev' into feature/ui_build
jboddey Jul 31, 2024
c8360d4
Merge branch 'dev' into feature/ui_build
jboddey Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ on:
push:
branches:
- 'dev'
- 'release/*'

permissions:
contents: read

jobs:
testrun_package:
create_package:
permissions: {}
name: Package
runs-on: ubuntu-22.04
Expand All @@ -28,3 +29,23 @@ jobs:
with:
name: testrun_package
path: testrun*.deb

install_package:
permissions: {}
needs: create_package
name: Install
runs-on: ubuntu-22.04
timeout-minutes: 15
steps:
- name: Checkout source
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Download package
uses: actions/download-artifact@v4
with:
name: testrun_package
- name: Install dependencies
shell: bash {0}
run: sudo cmd/prepare
- name: Install package
shell: bash {0}
run: sudo apt install ./testrun*.deb
10 changes: 7 additions & 3 deletions cmd/build
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ fi
# Builds all docker images
echo Building docker images

# Build user interface
echo Building user interface
if docker build -t test-run/ui -f modules/ui/ui.Dockerfile . ; then
# Check if UI has already been built (if -l was used during install)
if [ ! -d "modules/ui/dist" ]; then
cmd/build_ui
fi

# Build UI image
if docker build -t testrun/ui -f modules/ui/ui.Dockerfile . ; then
echo Successully built the user interface
else
echo An error occured whilst building the user interface
Expand Down
35 changes: 35 additions & 0 deletions cmd/build_ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash -e

# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Build the UI
echo Building the user interface

# Build UI builder image
if docker build -t testrun/build-ui -f modules/ui/build.Dockerfile . ; then
echo Successully built the ui builder
else
echo An error occured whilst building the ui builder
exit 1
fi

# Check that the container is not already running
docker kill tr-ui-build 2> /dev/null || true

# Start build container and build the ui dist
docker run -it --rm -v $PWD/modules/ui:/modules/ui testrun/build-ui /bin/sh -c "npm install && npm run build"
jboddey marked this conversation as resolved.
Show resolved Hide resolved

# Kill the container
docker kill tr-ui-build
18 changes: 16 additions & 2 deletions cmd/install
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,29 @@ echo Installing application dependencies
while getopts ":l" option; do
case $option in
l) # Install Testrun in local directory
TESTRUN_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/.. && pwd)
TESTRUN_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/.. && pwd)
esac
done

# Check if TESTRUN_DIR has been set, otherwise install in /usr/local/testrun
if [[ -z "${TESTRUN_DIR}" ]]; then
TESTRUN_DIR=/usr/local/testrun

# Check that user is sudo
if [[ "$EUID" -ne 0 ]]; then
echo "Installing Testrun in the default location requires sudo. Run using sudo cmd/install"
exit 1
fi

else
TESTRUN_DIR="${TESTRUN_DIR}"

# Check that user is in docker group
if ! (id -nGz "$USER" | grep -qzxF "docker"); then
echo User is not in docker group. Follow https://docs.docker.com/engine/install/linux-postinstall/ to finish setting up docker.
exit 1
fi

fi

echo Installing Testrun at $TESTRUN_DIR
Expand All @@ -51,7 +65,7 @@ cp -n local/system.json.example local/system.json
deactivate

# Build docker images
sudo cmd/build
cmd/build

# Create local folders
mkdir -p local/devices
Expand Down
13 changes: 11 additions & 2 deletions cmd/package
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

# Creates a package for Testrun

# Check that user is not root
if [[ "$EUID" == 0 ]]; then
echo "Must not run as root. Use cmd/package as regular user"
exit 1
fi

MAKE_SRC_DIR=make
MAKE_CONTROL_DIR=make/DEBIAN/control

Expand All @@ -25,10 +31,10 @@ version=$(grep -R "Version: " $MAKE_CONTROL_DIR | awk '{print $2}')
# Replace invalid characters
version="${version//./_}"

# Delete existing make files
rm -rf $MAKE_SRC_DIR/usr
echo Building package for testrun v${version}

# Delete existing make files
echo Cleaning up previous build files
rm -rf $MAKE_SRC_DIR/usr

# Copy testrun script to /bin
Expand Down Expand Up @@ -60,6 +66,9 @@ mkdir -p $MAKE_SRC_DIR/usr/local/testrun/local/risk_profiles
mkdir -p local/root_certs
cp -r local/root_certs $MAKE_SRC_DIR/usr/local/testrun/local/

# Build the UI
cmd/build_ui

# Copy framework and modules into testrun folder
cp -r {framework,modules} $MAKE_SRC_DIR/usr/local/testrun

Expand Down
2 changes: 1 addition & 1 deletion framework/python/src/core/testrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def start_ui(self):

try:
client.containers.run(
image='test-run/ui',
image='testrun/ui',
auto_remove=True,
jboddey marked this conversation as resolved.
Show resolved Hide resolved
name='tr-ui',
hostname='testrun.io',
Expand Down
5 changes: 3 additions & 2 deletions modules/ui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"budgets": [
{
"type": "initial",
"maximumWarning": "1000kb",
"maximumWarning": "1500kb",
"maximumError": "3000kb"
},
{
Expand Down Expand Up @@ -94,6 +94,7 @@
}
},
"cli": {
"schematicCollections": ["@angular-eslint/schematics"]
"schematicCollections": ["@angular-eslint/schematics"],
"analytics": false
}
}
20 changes: 20 additions & 0 deletions modules/ui/build.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Image name: testrun/build-ui
FROM node@sha256:ffebb4405810c92d267a764b21975fb2d96772e41877248a37bf3abaa0d3b590 as build

# Set the working directory
WORKDIR /modules/ui

11 changes: 2 additions & 9 deletions modules/ui/ui.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Image name: test-run/ui
FROM node@sha256:ffebb4405810c92d267a764b21975fb2d96772e41877248a37bf3abaa0d3b590 as build

WORKDIR /modules/ui
COPY modules/ui/ /modules/ui
RUN npm install
RUN npm run build

# Image name: testrun/ui
FROM nginx@sha256:4c0fdaa8b6341bfdeca5f18f7837462c80cff90527ee35ef185571e1c327beac

COPY --from=build /modules/ui/dist/ /usr/share/nginx/html
COPY modules/ui/dist/ /usr/share/nginx/html

EXPOSE 8080

Expand Down
Loading