This is an automated email from the ASF dual-hosted git repository.
ocket8888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 435a8b0 CiaB CI: Build images in a separate action (#5078)
435a8b0 is described below
commit 435a8b0ff6bfd5a0a7a8cd5c189154ae0bb733a9
Author: Zach Hoffman <[email protected]>
AuthorDate: Wed Sep 30 00:16:10 2020 -0600
CiaB CI: Build images in a separate action (#5078)
* Action to build CDN-in-a-Box images
* Make run-ciab a JavaScript action to avoid nested Docker
* Build images for CDN-in-a-Box in a separate action before running it
* Wait 12 minutes for the readiness container to exit instead of 10 minutes
* Simplify map
* Double quotes
* - Simplify setting DOCKER_BUILDKIT and COMPOSE_DOCKER_CLI_BUILD
- Do note use a template literal for console.error()
* Use path.basename() to get the RPM filename
* Use forEach() instead of map() since we don't need the result
---
.github/actions/{run-ciab => build-ciab}/README.md | 8 ++--
.../Dockerfile => build-ciab/action.yaml} | 14 ++----
.github/actions/build-ciab/build-ciab.js | 54 ++++++++++++++++++++++
.github/actions/build-rpms/main.js | 4 +-
.github/actions/run-ciab/README.md | 2 +-
.github/actions/run-ciab/action.yaml | 8 ++--
.../{build-rpms/main.js => run-ciab/run-ciab.js} | 17 ++-----
.../run-ciab/{entrypoint.sh => run-ciab.sh} | 15 +-----
.github/workflows/ciab.yaml | 2 +
9 files changed, 77 insertions(+), 47 deletions(-)
diff --git a/.github/actions/run-ciab/README.md
b/.github/actions/build-ciab/README.md
similarity index 79%
copy from .github/actions/run-ciab/README.md
copy to .github/actions/build-ciab/README.md
index b4e479a..36b2596 100644
--- a/.github/actions/run-ciab/README.md
+++ b/.github/actions/build-ciab/README.md
@@ -17,9 +17,9 @@
under the License.
-->
-# run-ciab Docker action
+# build-ciab JavaScript action
-This action runs the CDN-in-a-Box and exits with the exit code from the
`readiness` service.
+This action builds the CDN-in-a-Box images. It assumes the RPMs are already
built and exist in artifacts in the `dist/` directory.
## Inputs
None
@@ -27,9 +27,9 @@ None
## Outputs
### `exit-code`
-Exit code of the script
+Exit code from building the images
## Example usage
```yaml
-uses: .github/actions/run-ciab
+uses: .github/actions/build-ciab
```
diff --git a/.github/actions/run-ciab/Dockerfile
b/.github/actions/build-ciab/action.yaml
similarity index 81%
rename from .github/actions/run-ciab/Dockerfile
rename to .github/actions/build-ciab/action.yaml
index e7f7d3d..3076807 100644
--- a/.github/actions/run-ciab/Dockerfile
+++ b/.github/actions/build-ciab/action.yaml
@@ -15,12 +15,8 @@
# specific language governing permissions and limitations
# under the License.
-FROM docker:stable
-
-VOLUME /var/run/docker.sock:/var/run/docker.sock
-RUN apk add make docker-compose git
-
-COPY entrypoint.sh /
-RUN chmod a+x /entrypoint.sh
-
-ENTRYPOINT /entrypoint.sh
+name: build-ciab
+description: Builds CDN-in-a-Box images for the standard CiaB services and the
readiness service
+runs:
+ using: node12
+ main: build-ciab.js
diff --git a/.github/actions/build-ciab/build-ciab.js
b/.github/actions/build-ciab/build-ciab.js
new file mode 100644
index 0000000..6bd2e94
--- /dev/null
+++ b/.github/actions/build-ciab/build-ciab.js
@@ -0,0 +1,54 @@
+/*
+* 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
+*
+* http://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.
+*/
+
+"use strict";
+const child_process = require("child_process");
+const fs = require("fs");
+const path = require("path");
+const spawnOptions = {
+ stdio: "inherit",
+ stderr: "inherit"
+};
+const dockerCompose = ["docker-compose", "-f", "docker-compose.yml", "-f",
"docker-compose.readiness.yml"];
+process.env.DOCKER_BUILDKIT = 1;
+process.env.COMPOSE_DOCKER_CLI_BUILD = 1;
+
+function moveRPMs() {
+ process.chdir(`${process.env.GITHUB_WORKSPACE}/dist`);
+ fs.readdirSync(".") // read contents of the dist directory
+ .filter(item => fs.lstatSync(item).isDirectory()) // get a list
of directories within dist
+ .flatMap(directory => fs.readdirSync(directory).map(item =>
path.join(directory, item))) // list files within those directories
+ .filter(item => /\.rpm$/.test(item)) // get a list of RPMs
+ .forEach(rpm => fs.renameSync(rpm, path.basename(rpm))); //
move the RPMs to the dist folder
+}
+
+function runProcess(...commandArguments) {
+ console.info(...commandArguments);
+ const proc = child_process.spawnSync(
+ commandArguments[0],
+ commandArguments.slice(1),
+ spawnOptions
+ );
+ if (proc.status === 0) {
+ return;
+ }
+ console.error("Child process", ...commandArguments, "exited with status
code", proc.status, "!");
+ process.exit(proc.status);
+}
+
+moveRPMs();
+process.chdir(`${process.env.GITHUB_WORKSPACE}/infrastructure/cdn-in-a-box`);
+runProcess("make"); // Place the RPMs for docker-compose build. All RPMs
should have already been built.
+runProcess(...dockerCompose, "build", "--parallel");
+
diff --git a/.github/actions/build-rpms/main.js
b/.github/actions/build-rpms/main.js
index a80b34b..b352a64 100644
--- a/.github/actions/build-rpms/main.js
+++ b/.github/actions/build-rpms/main.js
@@ -14,7 +14,7 @@
"use strict";
const child_process = require("child_process");
-const spawnArgs = {
+const spawnOptions = {
stdio: "inherit",
stderr: "inherit",
};
@@ -30,6 +30,6 @@ dockerComposeArgs.push(atcComponent);
const proc = child_process.spawnSync(
"docker-compose",
dockerComposeArgs,
- spawnArgs
+ spawnOptions
);
process.exit(proc.status);
diff --git a/.github/actions/run-ciab/README.md
b/.github/actions/run-ciab/README.md
index b4e479a..565e86c 100644
--- a/.github/actions/run-ciab/README.md
+++ b/.github/actions/run-ciab/README.md
@@ -17,7 +17,7 @@
under the License.
-->
-# run-ciab Docker action
+# run-ciab JavaScript action
This action runs the CDN-in-a-Box and exits with the exit code from the
`readiness` service.
diff --git a/.github/actions/run-ciab/action.yaml
b/.github/actions/run-ciab/action.yaml
index 527a331..7078e46 100644
--- a/.github/actions/run-ciab/action.yaml
+++ b/.github/actions/run-ciab/action.yaml
@@ -15,8 +15,8 @@
# specific language governing permissions and limitations
# under the License.
-name: 'run-ciab'
-description: 'Runs CDN-in-a-Box'
+name: run-ciab
+description: Runs CDN-in-a-Box
runs:
- using: 'docker'
- image: 'Dockerfile'
+ using: node12
+ main: run-ciab.js
diff --git a/.github/actions/build-rpms/main.js
b/.github/actions/run-ciab/run-ciab.js
similarity index 57%
copy from .github/actions/build-rpms/main.js
copy to .github/actions/run-ciab/run-ciab.js
index a80b34b..555278e 100644
--- a/.github/actions/build-rpms/main.js
+++ b/.github/actions/run-ciab/run-ciab.js
@@ -14,22 +14,11 @@
"use strict";
const child_process = require("child_process");
-const spawnArgs = {
+const path = require("path");
+const spawnOptions = {
stdio: "inherit",
stderr: "inherit",
};
-let atcComponent = process.env.ATC_COMPONENT;
-const dockerComposeArgs = ["-f",
`${process.env.GITHUB_WORKSPACE}/infrastructure/docker/build/docker-compose.yml`,
"run", "--rm"];
-if (typeof atcComponent !== "string" || atcComponent.length === 0) {
- console.error("Missing environment variable ATC_COMPONENT");
- process.exit(1);
-}
-atcComponent += "_build";
-dockerComposeArgs.push(atcComponent);
-const proc = child_process.spawnSync(
- "docker-compose",
- dockerComposeArgs,
- spawnArgs
-);
+const proc = child_process.spawnSync(path.join(__dirname, "run-ciab.sh"), [],
spawnOptions);
process.exit(proc.status);
diff --git a/.github/actions/run-ciab/entrypoint.sh
b/.github/actions/run-ciab/run-ciab.sh
similarity index 80%
rename from .github/actions/run-ciab/entrypoint.sh
rename to .github/actions/run-ciab/run-ciab.sh
index 33acdc5..64060ed 100755
--- a/.github/actions/run-ciab/entrypoint.sh
+++ b/.github/actions/run-ciab/run-ciab.sh
@@ -26,27 +26,16 @@ store_ciab_logs() {
done;
}
-export COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 # use Docker BuildKit for
better image building performance
-(
-cd dist;
-mv -- */*.rpm .;
-);
-
-docker-compose --version;
cd infrastructure/cdn-in-a-box;
-make; # All RPMs should have already been built
-
-docker images;
logged_services='trafficrouter readiness';
other_services='dns edge enroller mid-01 mid-02 origin trafficmonitor
trafficops trafficops-perl trafficstats trafficvault';
docker_compose='docker-compose -f ./docker-compose.yml -f
./docker-compose.readiness.yml';
-time $docker_compose build --parallel $logged_services $other_services;
$docker_compose up -d $logged_services $other_services;
$docker_compose logs -f $logged_services &
echo 'Waiting for the readiness container to exit...';
-if ! timeout 10m $docker_compose logs -f readiness >/dev/null; then
- echo "CDN-in-a-Box didn't become ready within 10 minutes - exiting" >&2;
+if ! timeout 12m $docker_compose logs -f readiness >/dev/null; then
+ echo "CDN-in-a-Box didn't become ready within 12 minutes - exiting" >&2;
exit_code=1;
store_ciab_logs;
elif exit_code="$(docker inspect --format='{{.State.ExitCode}}'
"$($docker_compose ps -q readiness)")"; [ "$exit_code" -ne 0 ]; then
diff --git a/.github/workflows/ciab.yaml b/.github/workflows/ciab.yaml
index 465f104..d2d479b 100644
--- a/.github/workflows/ciab.yaml
+++ b/.github/workflows/ciab.yaml
@@ -193,6 +193,8 @@ jobs:
uses: actions/download-artifact@v2
with:
path: ${{ github.workspace }}/dist/
+ - name: Build CDN-in-a-Box images
+ uses: ./.github/actions/build-ciab
- name: Start CDN-in-a-Box
uses: ./.github/actions/run-ciab
- name: Upload CDN-in-a-Box logs