-
Notifications
You must be signed in to change notification settings - Fork 161
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
maxandersen
wants to merge
1
commit into
jbangdev:main
Choose a base branch
from
maxandersen:betterdocker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ bin | |
homebrew-tap | ||
RESULTS | ||
*.db | ||
jbang-action | ||
out | ||
node_modules | ||
package-lock.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/jreleaser/distributions/jbang-action/docker/Dockerfile.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
73
src/jreleaser/distributions/jbang-action/docker/README.md.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
``` |
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
src/jreleaser/distributions/jbang-action/docker/entrypoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "${@}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# {{jreleaserCreationStamp}} | ||
FROM {{dockerBaseImage}} | ||
|
||
{{#dockerLabels}} | ||
|
@@ -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 | ||
|
||
ENV PATH="${PATH}:/jbang/bin" | ||
|
||
## github action does not allow writing to $HOME thus routing this elsewhere | ||
ENV JBANG_DIR="/jbang/.jbang" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}}"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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