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

feat: introduce clean docker multi java version build #1654

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ bin
homebrew-tap
RESULTS
*.db
jbang-action
out
node_modules
package-lock.json
Expand Down
43 changes: 40 additions & 3 deletions jreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,40 @@ files:

distributions:
jbang:
extraProperties:
# Key will be capitalized and prefixed with `distribution`, i.e, `distributionFoo`.
foo: bar
executable:
windowsExtension: cmd
docker: ## not ready to release this way.
docker:
active: RELEASE
continueOnError: true
templateDirectory: src/jreleaser/distributions/jbang/docker
postCommands:
- "VOLUME /scripts"
baseImage: "adoptopenjdk:11-jdk-hotspot"
registries:
- serverName: quay.io
- serverName: docker.io
- serverName: gcr.io
repository:
name: jbang-action
name: jbang-docker
specs:
java-11:
baseImage: "eclipse-temurin:11"
templateDirectory: src/jreleaser/distributions/jbang/docker
imageNames:
- 'jbangdev/jbang:{{tagName}}-{{dockerSpecName}}'
matchers:
foo: bar
java-17:
baseImage: "eclipse-temurin:17"
templateDirectory: src/jreleaser/distributions/jbang/docker
imageNames:
- 'jbangdev/jbang:{{tagName}}-{{dockerSpecName}}'
- 'jbangdev/jbang:{{tagName}}'
- 'jbangdev/jbang:latest'
matchers:
foo: bar
sdkman:
active: RELEASE
continueOnError: true
Expand Down Expand Up @@ -104,3 +128,16 @@ distributions:
artifacts:
- path: build/distributions/jbang-{{projectVersion}}.zip
- path: build/distributions/jbang-{{projectVersion}}.tar
jbang-action:
docker: ## not ready to release this way.
active: RELEASE
continueOnError: true
postCommands:
- "VOLUME /scripts"
baseImage: "adoptopenjdk:11-jdk-hotspot"
repository:
name: jbang-action
artifacts:
- path: build/distributions/jbang-{{projectVersion}}.zip
- path: build/distributions/jbang-{{projectVersion}}.tar

37 changes: 37 additions & 0 deletions src/jreleaser/distributions/jbang-action/docker/Dockerfile.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM {{dockerBaseImage}}

{{#dockerLabels}}
LABEL {{.}}
{{/dockerLabels}}

{{#dockerPreCommands}}
{{.}}
{{/dockerPreCommands}}

COPY assembly/* /

RUN jar xf {{distributionArtifactFileName}}{{distributionArtifactFileExtension}} && \
rm {{distributionArtifactFileName}}{{distributionArtifactFileExtension}} && \
mv jbang-* jbang && \
chmod +x jbang/bin/jbang

{{#dockerPostCommands}}
{{.}}
{{/dockerPostCommands}}

ENV PATH="${PATH}:/{{distributionArtifactName}}/bin"

ADD ./entrypoint /bin/entrypoint

ENV SCRIPTS_HOME /scripts
ENV JBANG_VERSION {{projectVersion}}
ENV JBANG_PATH=/jbang/bin

VOLUME /scripts

ENV PATH="${PATH}:/jbang/bin"

## github action does not allow writing to $HOME thus routing this elsewhere
ENV JBANG_DIR="/jbang/.jbang"

ENTRYPOINT ["entrypoint"]
73 changes: 73 additions & 0 deletions src/jreleaser/distributions/jbang-action/docker/README.md.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# JBang Container for Docker and Github Action

[![GitHub release badge](https://badgen.net/github/release/jbangdev/jbang-action/stable)](https://github.com/jbangdev/jbang-action/releases/latest)
[![GitHub license badge](https://badgen.net/github/license/jbangdev/jbang-action)]()
[![GitHub Workflows badge](https://badgen.net/runkit/maxandersen/61b3c9809073c8000ae9b210)](https://github.com/search?q=jbang-action+language%3AYAML+language%3AYAML+path%3A.github%2Fworkflows&type=Code&ref=advsearch&l=&l=)
[![DockerHub Pulls](https://img.shields.io/docker/pulls/jbangdev/jbang-action)]()

This container intended for quick and easily run java based scripts with [jbang](https://jbang.dev).

Can be used directly with docker or as a GitHub Action.

The source is located in [jbangdev/jbang](https://github.com/jbangdev/jbang/blob/HEAD/src/jreleaser/distributions/jbang/docker/) and are updated in this repo on every tag/release of jbangdev/jbang.


[Source](https://github.com/jbangdev/jbang-action)

## Container/Docker usage

Using dockerhub images:

```
docker run -v `pwd`:/ws --workdir=/ws jbangdev/jbang-action helloworld.java
```

Using quay.io images:

```
docker run -v `pwd`:/ws --workdir=/ws quay.io/jbangdev/jbang-action helloworld.java
```


## Github Action

### Inputs

Key | Example | Description
----|---------|------------
trust | `https://github.com/maxandersen` | Host pattern to add to be trusted before the script are executed.
jbangargs | `--verbose` | Arguments to pass to jbang before the script.
script | `hello.java` | File, URL or alias referring to script to run
scriptargs | `--token ${GITHUB_TOKEN}` | Arguments to pass to the script. Note: due to how github actions + docker arguments containing spaces gets treated as separate arguments no matter how much quoting is done. If you need argument with spaces better to extend the docker file and call jbang directly.

### Outputs

### Example usage

Here it is assumed you have a jbang script called `createissue.java` in the root of your project.

```yaml
on: [push]

jobs:
jbang:
runs-on: ubuntu-latest
name: A job to run jbang
steps:
- name: checkout
uses: actions/checkout@v1
- uses: actions/cache@v1
with:
path: /root/.jbang
key: ${{ runner.os }}-jbang-${{ hashFiles('*.java') }}
restore-keys: |
${{ runner.os }}-jbang-
- name: jbang
uses: jbangdev/jbang-action@{{tagName}}
with:
script: createissue.java
scriptargs: "my world"
env:
JBANG_REPO: /root/.jbang/repository
GITHUB_TOKEN: ${{ secrets.ISSUE_GITHUB_TOKEN }}
```
21 changes: 21 additions & 0 deletions src/jreleaser/distributions/jbang-action/docker/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# In OpenShift, containers are run as a random high number uid
# that doesn't exist in /etc/passwd
if [ `id -u` -ge 500 ] || [ -z "${CURRENT_UID}" ]; then

cat << EOF > /tmp/passwd
root:x:0:0:root:/root:/bin/bash
jbang:x:`id -u`:`id -g`:,,,:/scripts:/bin/bash
EOF

cat /tmp/passwd > /etc/passwd
rm /tmp/passwd
fi

if [[ ! -z "$INPUT_TRUST" ]]; then
$JBANG_PATH/jbang trust add $INPUT_TRUST
fi

echo jbang $INPUT_JBANGARGS $INPUT_SCRIPT $INPUT_ARGS "${@}"
exec $JBANG_PATH/jbang $INPUT_JBANGARGS $INPUT_SCRIPT $INPUT_SCRIPTARGS "${@}"
25 changes: 6 additions & 19 deletions src/jreleaser/distributions/jbang/docker/Dockerfile.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# {{jreleaserCreationStamp}}
FROM {{dockerBaseImage}}

{{#dockerLabels}}
Expand All @@ -8,30 +9,16 @@ LABEL {{.}}
{{.}}
{{/dockerPreCommands}}

COPY assembly/* /
COPY assembly/ /

RUN jar xf {{distributionArtifactFileName}}{{distributionArtifactFileExtension}} && \
rm {{distributionArtifactFileName}}{{distributionArtifactFileExtension}} && \
mv jbang-* jbang && \
chmod +x jbang/bin/jbang

chmod +x {{distributionArtifactRootEntryName}}/bin/{{distributionExecutableUnix}}

{{#dockerPostCommands}}
{{.}}
{{/dockerPostCommands}}

ENV PATH="${PATH}:/{{distributionArtifactName}}/bin"

ADD ./entrypoint /bin/entrypoint

ENV SCRIPTS_HOME /scripts
ENV JBANG_VERSION {{projectVersion}}
ENV JBANG_PATH=/jbang/bin

VOLUME /scripts
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to keep /scripts


ENV PATH="${PATH}:/jbang/bin"

## github action does not allow writing to $HOME thus routing this elsewhere
ENV JBANG_DIR="/jbang/.jbang"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check if this is still required.

ENV PATH="${PATH}:/{{distributionArtifactRootEntryName}}/bin"

ENTRYPOINT ["entrypoint"]
ENTRYPOINT ["/{{distributionArtifactRootEntryName}}/bin/{{distributionExecutableUnix}}"]
15 changes: 6 additions & 9 deletions src/jreleaser/distributions/jbang/docker/README.md.tpl
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
# JBang Container for Docker and Github Action

[![GitHub release badge](https://badgen.net/github/release/jbangdev/jbang-action/stable)](https://github.com/jbangdev/jbang-action/releases/latest)
[![GitHub license badge](https://badgen.net/github/license/jbangdev/jbang-action)]()
[![GitHub Workflows badge](https://badgen.net/runkit/maxandersen/61b3c9809073c8000ae9b210)](https://github.com/search?q=jbang-action+language%3AYAML+language%3AYAML+path%3A.github%2Fworkflows&type=Code&ref=advsearch&l=&l=)
[![DockerHub Pulls](https://img.shields.io/docker/pulls/jbangdev/jbang-action)]()
[![GitHub release badge](https://badgen.net/github/release/jbangdev/jbang-docker/stable)](https://github.com/jbangdev/jbang-docker/releases/latest)
[![GitHub license badge](https://badgen.net/github/license/jbangdev/jbang-docker)]()
[![DockerHub Pulls](https://img.shields.io/docker/pulls/jbangdev/jbang-docker)]()

This container intended for quick and easily run java based scripts with [jbang](https://jbang.dev).

Can be used directly with docker or as a GitHub Action.

The source is located in [jbangdev/jbang](https://github.com/jbangdev/jbang/blob/HEAD/src/jreleaser/distributions/jbang/docker/) and are updated in this repo on every tag/release of jbangdev/jbang.


[Source](https://github.com/jbangdev/jbang-action)
[Source](https://github.com/jbangdev/jbang-docker)

## Container/Docker usage

Using dockerhub images:

```
docker run -v `pwd`:/ws --workdir=/ws jbangdev/jbang-action helloworld.java
docker run -v `pwd`:/ws --workdir=/ws jbangdev/jbang helloworld.java
```

Using quay.io images:

```
docker run -v `pwd`:/ws --workdir=/ws quay.io/jbangdev/jbang-action helloworld.java
docker run -v `pwd`:/ws --workdir=/ws quay.io/jbangdev/jbang helloworld.java
```


Expand Down
7 changes: 3 additions & 4 deletions src/jreleaser/distributions/jbang/docker/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ EOF
rm /tmp/passwd
fi

if [[ ! -z "$INPUT_TRUST" ]]; then
$JBANG_PATH/jbang trust add $INPUT_TRUST
if [[ ! -z "$TRUST" ]]; then
jbang trust add $TRUST
fi

echo jbang $INPUT_JBANGARGS $INPUT_SCRIPT $INPUT_ARGS "${@}"
exec $JBANG_PATH/jbang $INPUT_JBANGARGS $INPUT_SCRIPT $INPUT_SCRIPTARGS "${@}"
exec jbang "${@}"
Loading