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

Add feature to tag image with multiple tags #21

Merged
merged 5 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: [
"@redhat-actions/eslint-config",
],
};
42 changes: 37 additions & 5 deletions .github/workflows/verify-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
name: Test Build
on: [push, pull_request, workflow_dispatch]
env:
TEST_REPO: spring-petclinic
PROJECT_DIR: spring-petclinic
IMAGE_NAME: spring-petclinic
MVN_REPO_DIR: ~/.m2/repository

jobs:
build:
Expand All @@ -24,7 +25,22 @@ jobs:
uses: actions/checkout@v2
with:
repository: "spring-projects/spring-petclinic"
path: ${{ env.TEST_REPO }}
path: ${{ env.PROJECT_DIR }}

# If none of these files has changed, we assume that the contents of
# .m2/repository can be fetched from the cache.
- name: Hash Maven files
working-directory: ${{ env.PROJECT_DIR }}
run: |
echo "MVN_HASH=${{ hashFiles('**/pom.xml', '.mvn/**/*', 'mvnw*') }}" >> $GITHUB_ENV

# Download the m2 repository from the cache to speed up the build.
- name: Check for Maven cache
id: check-mvn-cache
uses: actions/cache@v2
with:
path: ${{ env.MVN_REPO_DIR }}
key: ${{ env.MVN_HASH }}

# Setup java.
- name: Setup Java
Expand All @@ -34,23 +50,39 @@ jobs:

# Run maven to build the project
- name: Maven
working-directory: ${{ env.TEST_REPO }}
working-directory: ${{ env.PROJECT_DIR }}
run: |
mvn package -ntp -B

# If there was no cache hit above, store the output into the cache now.
- name: Save Maven repo into cache
if: ${{ steps.check-mvn-cache.outputs.cache-hit }} != 'true'
uses: actions/cache@v2
with:
path: ${{ env.MVN_REPO_DIR }}
key: ${{ env.MVN_HASH }}

# Build image using Buildah action
- name: Build Image
id: build_image
uses: ./buildah-build/
with:
image: ${{ env.IMAGE_NAME }}
tags: 'latest ${{ github.sha }}'
base-image: 'registry.access.redhat.com/openjdk/openjdk-11-rhel7'
# To avoid hardcoding a particular version of the binary.
content: |
./spring-petclinic/target/spring-petclinic-*.BUILD-SNAPSHOT.jar
./spring-petclinic/target/spring-petclinic-*.jar
entrypoint: |
java
-jar
spring-petclinic-*.BUILD-SNAPSHOT.jar
spring-petclinic-*.jar
port: 8080

- name: Echo Outputs
run: |
echo "Image: ${{ steps.build_image.outputs.image }}"
echo "Tags: ${{ steps.build_image.outputs.tags }}"

# Check if image is build
- name: Check images created
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ After building your image, use [push-to-registry](https://github.com/redhat-acti
</tr>

<tr>
<td>tag</td>
<td>tags</td>
<td>No</td>
<td>
Tag to give to the output image.<br>
The tags of the image to build. For multiple tags, separate by a space. For example, <code>latest ${{ github.sha }}</code>.<br>
Default: <code>latest</code>
</td>
</tr>

<tr>
<td>base-image</td>
<td>No</td>
<td>The base image to use to create the initial container. If not specified, the action will try to pick one automatically. (N.B: At this time the action is only able to auto select Java base image)</td>
<td>The base image to use for the container.</td>
</tr>

<tr>
Expand Down Expand Up @@ -118,6 +118,14 @@ envs: |
</tr>
</table>

## 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 }}`.

## Build Types

You can configure the `buildah` action to build your image using one or more Dockerfiles, or none at all.
Expand All @@ -144,7 +152,7 @@ jobs:
uses: redhat-actions/buildah-build@v1
with:
image: my-new-image
tag: v1
tags: v1 ${{ github.sha }}
dockerfiles: |
./Dockerfile
build-args: |
Expand Down Expand Up @@ -186,7 +194,7 @@ jobs:
with:
base-image: docker.io/fabric8/java-alpine-openjdk11-jre
image: my-new-image
tag: v1
tags: v1
content: |
target/spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar
entrypoint: java -jar spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar
Expand Down
15 changes: 10 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ inputs:
image:
description: 'The name (reference) of the image to build'
required: true
tag:
description: 'The tag of the image to build'
tags:
description: 'The tags of the image to build. For multiple tags, seperate by a space. For example, "latest v1".'
required: false
default: latest
base-image:
description: 'The base image to use to create a new container image'
required: false
required: true
dockerfiles:
description: 'List of Dockerfile paths (eg: ./Dockerfile)'
required: false
Expand All @@ -38,12 +38,17 @@ inputs:
description: 'List of environment variables to be set when running containers based on image'
required: false
build-args:
description: 'List of --build-args to pass to buildah.'
description: 'List of --build-args to pass to buildah'
required: false
oci:
description: 'Set to true to build using the OCI image format instead of the Docker image format.'
description: 'Set to true to build using the OCI image format instead of the Docker image format'
default: 'false'
required: false
outputs:
image:
description: 'Name of the image built'
tags:
description: 'List of the tags that were created, separated by spaces'
runs:
using: 'node12'
main: 'dist/index.js'
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.

3 changes: 0 additions & 3 deletions language-image.json

This file was deleted.

Loading