Skip to content

Commit

Permalink
Install s2i if not already installed (#34)
Browse files Browse the repository at this point in the history
* Install s2i if not already installed

Signed-off-by: divyansh42 <[email protected]>
  • Loading branch information
divyansh42 authored Jun 8, 2021
1 parent 26f38de commit ce792f9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/verify-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ jobs:
path: 's2i-build'

# Checkout hello-world repository for testing
- name: Checkout
- name: Checkout application
uses: actions/checkout@v2
with:
repository: 'go-training/helloworld'
path: ${{ env.TEST_REPO }}

# Setup S2i and Build container image
- name: Setup and Build
# Install s2i cli for future steps
- name: Install S2i
uses: redhat-actions/openshift-tools-installer@v1
with:
source: github
github_pat: ${{ github.token }}
s2i: "latest"

# Build container image
- name: Build
id: build_image
uses: ./s2i-build/
with:
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ building and running the source code.

This Action will install [the latest](https://github.com/openshift/source-to-image/releases/tag/v1.3.1) version of S2I.

To install any specific version of `s2i` use [**openshift-tools-installer**](https://github.com/marketplace/actions/openshift-client-installer).

**NOTE:**
`s2i-build` only works on Linux platforms, because it relies on the Docker daemon.<br>
If you are using GitHub's Ubuntu runners, the Docker daemon will already be available.
Otherwise, you can use [Docker Setup Buildx](https://github.com/marketplace/actions/docker-setup-buildx) to set up and start the Docker daemon.
Otherwise, you can use [docker-setup-buildx](https://github.com/marketplace/actions/docker-setup-buildx) to set up and start the Docker daemon.

Also see [buildah-build](https://github.com/redhat-actions/buildah-build) for more configurable method of building images, from scratch or from a Dockerfile.
Also see [**buildah-build**](https://github.com/marketplace/actions/buildah-build) for more configurable method of building images, from scratch or from a Dockerfile.

Once an image has been built, [push-to-registry](https://github.com/redhat-actions/push-to-registry) can be used to push it to an image registry.
Once an image has been built, [**push-to-registry**](https://github.com/marketplace/actions/push-to-registry) can be used to push it to an image registry.

<a id="action-inputs"></a>

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

28 changes: 20 additions & 8 deletions src/s2iExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*-----------------------------------------------------------------------------------------------*/
import * as core from "@actions/core";
import * as fs from "fs";
import * as io from "@actions/io";
import * as path from "path";
import { Command } from "./command";
import { Installer } from "./installer";
Expand All @@ -24,16 +25,27 @@ export async function run(): Promise<void> {

const tagsList: string[] = tags.split(" ");

const s2iVersion = "v1.3.1";
const binaryVersion: BinaryVersion = convertStringToBinaryVersion(s2iVersion);
const s2iBinary: FindBinaryStatus = await Installer.installS2i(binaryVersion, runnerOS);
let s2iPath = await io.which("s2i", false);

if (s2iBinary.found === false) {
throw new Error(getReason(s2iBinary));
if (s2iPath === "") {
const s2iVersion = "v1.3.1";
core.info(`⏳ s2i is not installed. Installing s2i ${s2iVersion}`);
const binaryVersion: BinaryVersion = convertStringToBinaryVersion(s2iVersion);
const s2iBinary: FindBinaryStatus = await Installer.installS2i(binaryVersion, runnerOS);

if (s2iBinary.found === false) {
throw new Error(getReason(s2iBinary));
}

core.info(`✅ Sucessfully installed s2i.`);

s2iPath = s2iBinary.path;
}
else {
core.info(`ℹ️ s2i is already installed, skipping installation`);
}
Installer.addS2iToPath(s2iBinary.path, runnerOS);
Installer.addS2iToPath(s2iPath, runnerOS);

core.debug(s2iVersion);
core.debug(runnerOS);

// info message if user doesn't provides any tag
Expand Down Expand Up @@ -62,7 +74,7 @@ export async function run(): Promise<void> {
buildCmd.push(envFilePath);
}

await Command.execute(s2iBinary.path, buildCmd);
await Command.execute(s2iPath, buildCmd);

if (tagsList.length > 1) {
await Command.tag(image, tagsList);
Expand Down

0 comments on commit ce792f9

Please sign in to comment.