First commit 🚀

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
divyansh42 2021-03-30 18:57:12 +05:30
commit 565d575198
20 changed files with 6476 additions and 0 deletions

5
.eslintrc.js Normal file
View file

@ -0,0 +1,5 @@
module.exports = {
extends: [
"@redhat-actions/eslint-config",
],
};

48
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,48 @@
name: CI checks
on:
push:
pull_request:
jobs:
lint:
name: Run ESLint
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- run: npm ci
- run: npm run lint
check-dist:
name: Check Distribution
runs-on: ubuntu-20.04
env:
BUNDLE_FILE: "dist/index.js"
BUNDLE_COMMAND: "npm run bundle"
steps:
- uses: actions/checkout@v2
- name: Install
run: npm ci
- name: Verify Latest Bundle
uses: redhat-actions/common/bundle-verifier@v1
with:
bundle_file: ${{ env.BUNDLE_FILE }}
bundle_command: ${{ env.BUNDLE_COMMAND }}
check-inputs-outputs:
name: Check Input and Output enums
runs-on: ubuntu-20.04
env:
IO_FILE: ./src/generated/inputs-outputs.ts
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: npm ci
- name: Verify Input and Output enums
uses: redhat-actions/common/action-io-generator@v1
with:
io_file: ${{ env.IO_FILE }}

30
.github/workflows/example.yml vendored Normal file
View file

@ -0,0 +1,30 @@
name: Test Login
on:
push:
workflow_dispatch:
env:
REGISTRY_USER: diagrawa
IMAGE_REGISTRY: quay.io
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
jobs:
build-and-push:
name: Build and push image to Quay.io
runs-on: ubuntu-20.04
steps:
# Checkout podman login action github repository
- name: Checkout Podman login action
uses: actions/checkout@v2
- name: Login to Quay.io
uses: ./
with:
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
registry: ${{ env.IMAGE_REGISTRY }}
- name: Verify
run: |
echo ${XDG_RUNTIME_DIR}/containers/auth.json

18
.github/workflows/link_check.yml vendored Normal file
View file

@ -0,0 +1,18 @@
name: Link checker
on:
push:
paths:
- '**.md'
pull_request:
paths:
-'**.md'
jobs:
markdown-link-check:
name: Check links in markdown
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-verbose-mode: true

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
node_modules/
out/

21
CHANGELOG.md Normal file
View file

@ -0,0 +1,21 @@
# buildah-build Changelog
## v2.2.1
- Add note about multi architecture(s) image built support [1f7c249](https://github.com/redhat-actions/buildah-build/commit/1f7c2499306a8def9affb31cc7d43934bb87907d)
## v2.2
- Add output message if tags is not provided [76570bc](https://github.com/redhat-actions/buildah-build/commit/76570bc65b73d4072c85224b6f6e2fef3cf2b24b)
## v2.1
- Add `archs` input to allow building images for custom architectures [803a141](https://github.com/redhat-actions/buildah-build/commit/803a1413e7c2a594cbfb6680bca358bfdbe36745)
## v2
- Rename `tag` input to `tags`, to allow you to build multiple tags of the same image
- Add outputs `image` and `tags`, which output the image name and all tags of the image that was created [88e0085](https://github.com/redhat-actions/buildah-build/commit/88e00855444b8d915b900c8251f48c291ccedce5)
- (Internal) Add CI checks to the action that includes ESlint, bundle verifier and IO checker [20a8e62](https://github.com/redhat-actions/buildah-build/commit/20a8e62ce082870ed0ff1ee141bb98ae95432501)
## v1
- Initial marketplace release
## v0.1
- Initial pre-release

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Red Hat. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE

161
README.md Normal file
View file

@ -0,0 +1,161 @@
# buildah-build
[![CI checks](https://github.com/redhat-actions/buildah-build/workflows/CI%20checks/badge.svg)](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3A%22CI+checks%22)
[![Build](https://github.com/redhat-actions/buildah-build/workflows/Build/badge.svg)](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3ABuild)
[![Build from dockerfile](https://github.com/redhat-actions/buildah-build/workflows/Build%20from%20dockerfile/badge.svg)](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3A%22Build+from+dockerfile%22)
[![Link checker](https://github.com/redhat-actions/buildah-build/workflows/Link%20checker/badge.svg)](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3A%22Link+checker%22)
<br>
<br>
[![tag badge](https://img.shields.io/github/v/tag/redhat-actions/buildah-build)](https://github.com/redhat-actions/buildah-build/tags)
[![license badge](https://img.shields.io/github/license/redhat-actions/buildah-build)](./LICENSE)
[![size badge](https://img.shields.io/github/size/redhat-actions/buildah-build/dist/index.js)](./dist)
Buildah is a GitHub Action for building Docker and Kubernetes-compatible images quickly and easily.
Buildah only works on Linux. GitHub's [Ubuntu Environments](https://github.com/actions/virtual-environments#available-environments) (`ubuntu-18.04` and newer) come with buildah installed. If you are not using these environments, or if you want to use a different version, you must first [install buildah](https://github.com/containers/buildah/blob/master/install.md).
After building your image, use [push-to-registry](https://github.com/redhat-actions/push-to-registry) to push the image and make it pullable.
<a id="action-inputs"></a>
## Action Inputs
<a id="dockerfile-build-inputs"></a>
### Inputs for build from dockerfile
| Input Name | Description | Default |
| ---------- | ----------- | ------- |
| archs | Architecture(s) to build the image(s) for. For multiple architectures, separate by a comma. Refer to [Multi arch builds](#multi-arch-builds) to setup the `qemu-user-static` dependency. | `amd64`
| build-args | Build arguments to pass to the Docker build using `--build-arg`, if using a Dockerfile that requires ARGs. Use the form `arg_name=arg_value`, and separate arguments with newlines. | None
| context | Path to directory to use as the build context. | `.`
| dockerfiles | The list of Dockerfile paths to perform a build using docker instructions. This is a multiline input to allow multiple Dockerfiles. | **Must be provided**
| image | Name to give to the output image. | **Must be provided**
| layers | Set to true to cache intermediate layers during the build process. | None
| oci | Build the image using the OCI format, instead of the Docker format. By default, this is `false`, because images built using the OCI format have issues when published to Dockerhub. | `false`
| tags | The tags of the image to build. For multiple tags, separate by a space. For example, `latest ${{ github.sha }}` | `latest`
<a id="scratch-build-inputs"></a>
### Inputs for build without dockerfile
| Input Name | Description | Default |
| ---------- | ----------- | ------- |
| archs | Architecture(s) to build the image(s) for. For multiple architectures, separate by a comma. Refer to [Multi arch builds](#multi-arch-builds) to setup the `qemu-user-static` dependency. | `amd64`
| base-image | The base image to use for the container. | **Must be provided**
| content | Paths to files or directories to copy inside the container to create the file image. This is a multiline input to allow you to copy multiple files/directories.| None
| context | Path to directory to use as the build context. | `.`
| entrypoint | The entry point to set for the container. This is a multiline input; split arguments across lines. | None
| envs | The environment variables to be set when running the container. This is a multiline input to add multiple environment variables. | None
| image | Name to give to the output image. | **Must be provided**
| oci | Build the image using the OCI format, instead of the Docker format. By default, this is `false`, because images built using the OCI format have issues when published to Dockerhub. | `false`
| port | The port to expose when running the container. | None
| tags | The tags of the image to build. For multiple tags, separate by a space. For example, `latest ${{ github.sha }}` | `latest`
| workdir | The working directory to use within the container. | None
<a id="outputs"></a>
## Action Outputs
`image`: The name of the built image.<br>
For example, `spring-image`.
`tags`: A list of the tags that were created, separated by spaces.<br>
For example, `latest ${{ github.sha }}`.
<a id="build-types"></a>
## Build Types
You can configure the `buildah` action to build your image using one or more Dockerfiles, or none at all.
<a id="build-using-dockerfile"></a>
### Building using Dockerfiles
If you have been building your images with an existing Dockerfile, `buildah` can reuse your Dockerfile.
In this case the inputs needed are `image` and `dockerfiles`. `tag` is also recommended. If your Dockerfile requires ARGs, these can be passed using `build-arg`.
```yaml
name: Build Image using Dockerfile
on: [push]
jobs:
build:
name: Build image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Buildah Action
uses: redhat-actions/buildah-build@v2
with:
image: my-new-image
tags: v1 ${{ github.sha }}
dockerfiles: |
./Dockerfile
build-args: |
some_arg=some_value
```
<a id="scratch-build"></a>
### Building without a Dockerfile
Building without a Dockerfile requires additional inputs, that would normally be specified in the Dockerfile.
Do not set `dockerfiles` if you are doing a build from scratch. Otherwise those Dockerfiles will be used, and the inputs below will be ignored.
- An output `image` name and usually a `tag`.
- `base-image`
- In a Dockerfile, this would be the `FROM` directive.
- `content` to copy into the new image
- In a Dockerfile, this would be `COPY` directives.
- `entrypoint` so the container knows what command to run.
- In a Dockerfile, this would be the `ENTRYPOINT`.
- All other optional configuration inputs, such as `port`, `envs`, and `workdir`.
Example of building a Spring Boot Java app image:
```yaml
name: Build Image
on: [push]
jobs:
build-image:
name: Build image without Dockerfile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: mvn package
- name: Build Image
uses: redhat-actions/buildah-build@v2
with:
base-image: docker.io/fabric8/java-alpine-openjdk11-jre
image: my-new-image
tags: v1
content: |
target/spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar
entrypoint: java -jar spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar
port: 8080
```
<a id="multi-arch-builds"></a>
## Multi arch builds
If building for an architecture other than `amd64`, install `qemu-user-static` using the following command.
```
sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes
```
## Using private images
If your build requires a private image, you have to `docker login` in a step before running this action.
For example:
```yaml
- name: Log in to Red Hat Registry
run: echo "${{ secrets.REGISTRY_REDHAT_IO_PASSWORD }}" | docker login registry.redhat.io -u "${{ secrets.REGISTRY_REDHAT_IO_USER }}" --password-stdin
```

19
action.yml Normal file
View file

@ -0,0 +1,19 @@
name: 'Podman login'
description: 'GitHub Action to login against a container registry'
author: 'Red Hat'
branding:
icon: circle
color: red
inputs:
registry:
description: 'Server address of Docker registry. If not set then will default to Docker Hub'
required: false
username:
description: 'Username used to log against the Docker registry'
required: false
password:
description: 'Password or personal access token used to log against the Docker registry'
required: false
runs:
using: 'node12'
main: 'dist/index.js'

2
dist/index.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/index.js.map vendored Normal file

File diff suppressed because one or more lines are too long

3910
dist/sourcemap-register.js vendored Normal file

File diff suppressed because it is too large Load diff

11
git-hooks/pre-commit Normal file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env bash
### Copy this into .git/hooks and overwrite the empty one.
### This will ensure the bundle and ins-outs verification checks won't fail for you.
echo "----- Pre-commit -----"
set -ex
npx action-io-generator -o src/generated/inputs-outputs.ts
npm run lint
npm run bundle
git add -v dist/ src/generated

2026
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

38
package.json Normal file
View file

@ -0,0 +1,38 @@
{
"name": "podman-login",
"version": "1.0.0",
"engines": {
"node": "12"
},
"description": "GitHub Action to login against a container registry",
"repository": {
"type": "git",
"url": "https://github.com/redhat-actions/podman-login"
},
"main": "dist/index.js",
"scripts": {
"compile": "tsc -p .",
"bundle": "ncc build src/index.ts --source-map --minify",
"clean": "rm -rf out/ dist/",
"lint": "eslint . --max-warnings=0"
},
"keywords": [],
"author": "Red Hat",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
"@actions/io": "^1.0.2"
},
"devDependencies": {
"@redhat-actions/action-io-generator": "^1.5.0",
"@redhat-actions/eslint-config": "^1.2.11",
"@redhat-actions/tsconfig": "^1.1.1",
"@types/node": "^12",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"@vercel/ncc": "^0.25.1",
"eslint": "^7.18.0",
"typescript": "^4.0.5"
}
}

16
src/context.ts Normal file
View file

@ -0,0 +1,16 @@
import * as core from "@actions/core";
import { Inputs } from "./generated/inputs-outputs";
export interface ActionInputs {
registry: string;
username: string;
password: string;
}
export function getInputs(): ActionInputs {
return {
registry: core.getInput(Inputs.REGISTRY),
username: core.getInput(Inputs.USERNAME),
password: core.getInput(Inputs.PASSWORD),
};
}

View file

@ -0,0 +1,24 @@
// This file was auto-generated by action-io-generator. Do not edit by hand!
export enum Inputs {
/**
* Password or personal access token used to log against the Docker registry
* Required: false
* Default: None.
*/
PASSWORD = "password",
/**
* Server address of Docker registry. If not set then will default to Docker Hub
* Required: false
* Default: None.
*/
REGISTRY = "registry",
/**
* Username used to log against the Docker registry
* Required: false
* Default: None.
*/
USERNAME = "username",
}
export enum Outputs {
}

47
src/index.ts Normal file
View file

@ -0,0 +1,47 @@
/***************************************************************************************************
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
**************************************************************************************************/
import * as core from "@actions/core";
import * as io from "@actions/io";
import * as os from "os";
import { getInputs } from "./context";
import { execute } from "./utils";
let podmanPath: string | undefined;
async function getPodmanPath(): Promise<string> {
if (podmanPath == null) {
podmanPath = await io.which("podman", true);
await execute(podmanPath, [ "version" ]);
}
return podmanPath;
}
async function run(): Promise<void> {
if (os.platform() !== "linux") {
throw new Error("Only supported on linux platform");
}
const { registry, username, password } = getInputs();
const args = [
"login",
registry,
"-u",
username,
"-p",
password,
];
try {
await execute(await getPodmanPath(), args);
core.info(`✅ Successfully logged in to ${registry}`);
}
catch (err) {
core.error(`Failed to login to ${registry}`);
}
}
run().catch(core.setFailed);

66
src/utils.ts Normal file
View file

@ -0,0 +1,66 @@
/***************************************************************************************************
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
**************************************************************************************************/
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as path from "path";
interface ExecResult {
exitCode: number;
stdout: string;
stderr: string;
}
export async function execute(
executable: string,
args: string[],
execOptions: exec.ExecOptions & { group?: boolean } = {},
): Promise<ExecResult> {
let stdout = "";
let stderr = "";
const finalExecOptions = { ...execOptions };
finalExecOptions.ignoreReturnCode = true; // the return code is processed below
finalExecOptions.listeners = {
stdline: (line): void => {
stdout += `${line}\n`;
},
errline: (line): void => {
stderr += `${line}\n`;
},
};
if (execOptions.group) {
const groupName = [ executable, ...args ].join(" ");
core.startGroup(groupName);
}
try {
const exitCode = await exec.exec(executable, args, finalExecOptions);
if (execOptions.ignoreReturnCode !== true && exitCode !== 0) {
// Throwing the stderr as part of the Error makes the stderr show up in the action outline,
// which saves some clicking when debugging.
let error = `${path.basename(executable)} exited with code ${exitCode}`;
if (stderr) {
error += `\n${stderr}`;
}
throw new Error(error);
}
return {
exitCode,
stdout,
stderr,
};
}
finally {
if (execOptions.group) {
core.endGroup();
}
}
}

10
tsconfig.json Normal file
View file

@ -0,0 +1,10 @@
{
"extends": "@redhat-actions/tsconfig",
"compilerOptions": {
"rootDir": "src/",
"outDir": "out/"
},
"include": [
"src/"
],
}