├── .github └── workflows │ ├── publish.yaml │ ├── updatequay.java │ └── verify.yml ├── .gitignore ├── Dockerfile ├── Dockerfile-remote ├── LICENSE ├── README.md ├── action.yml ├── assembly └── jbang-0.132.1.zip ├── container-structure-test.yaml └── entrypoint /.github/workflows/publish.yaml: -------------------------------------------------------------------------------- 1 | name: Update Docker Hub and Quay.io Description + github release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@master 14 | 15 | - name: Docker Hub Description 16 | if: success() 17 | continue-on-error: true 18 | uses: peter-evans/dockerhub-description@v3 19 | with: 20 | username: ${{ secrets.DOCKER_USERNAME }} 21 | password: ${{ secrets.DOCKER_PASSWORD }} 22 | repository: jbangdev/jbang-action 23 | 24 | - name: Login to Quay.io 25 | uses: actions-hub/docker/login@master 26 | env: 27 | DOCKER_USERNAME: ${{ secrets.QUAY_USERNAME }} 28 | DOCKER_PASSWORD: ${{ secrets.QUAY_PASSWORD }} 29 | DOCKER_REGISTRY_URL: quay.io 30 | 31 | - name: Update quay.io Description 32 | if: success() 33 | continue-on-error: true 34 | uses: jbangdev/jbang-action@v0.49.0 35 | with: 36 | script: .github/workflows/updatequay.java 37 | args: "--token $TOKEN" 38 | env: 39 | TOKEN: ${{ secrets.QUAY_TOKEN }} 40 | 41 | - name: Github Release 42 | if: success() && startsWith(github.ref, 'refs/tags/v') 43 | uses: ncipollo/release-action@v1 44 | with: 45 | body: ${{ format('See https://github.com/jbangdev/jbang/releases/tag/v{0}', env.IMAGE_TAG) }} 46 | token: ${{ secrets.GITHUB_TOKEN }} 47 | 48 | - uses: actions/cache@v4 49 | with: 50 | path: /root/.jbang 51 | key: ${{ runner.os }}-jbang-${{ hashFiles('**/*.java') }} 52 | restore-keys: | 53 | ${{ runner.os }}-jbang- 54 | -------------------------------------------------------------------------------- /.github/workflows/updatequay.java: -------------------------------------------------------------------------------- 1 | //usr/bin/env jbang "$0" "$@" ; exit $? 2 | //DEPS info.picocli:picocli:4.1.4 net.dongliu:requests:5.0.8 3 | //DEPS com.fasterxml.jackson.core:jackson-databind:2.9.8 4 | //JAVA_OPTIONS -Djava.util.logging.config.file=log.properties 5 | 6 | import picocli.CommandLine; 7 | import picocli.CommandLine.Command; 8 | import picocli.CommandLine.Option; 9 | import picocli.CommandLine.Parameters; 10 | 11 | import java.io.File; 12 | import java.nio.file.Files; 13 | import java.nio.file.Path; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | import java.util.concurrent.Callable; 17 | 18 | import com.fasterxml.jackson.databind.JsonNode; 19 | import com.fasterxml.jackson.databind.ObjectMapper; 20 | 21 | import net.dongliu.requests.Requests; 22 | 23 | @Command(name = "updatequay", mixinStandardHelpOptions = true, version = "updatequay 0.1", 24 | description = "updatequay made with jbang") 25 | class updatequay implements Callable { 26 | 27 | @Option(names="--token", required = true) 28 | private String token; 29 | 30 | public static void main(String... args) { 31 | int exitCode = new CommandLine(new updatequay()).execute(args); 32 | System.exit(exitCode); 33 | } 34 | 35 | @Override 36 | public Integer call() throws Exception { // your business logic goes here... 37 | 38 | // set headers by map 39 | Map headers = new HashMap<>(); 40 | headers.put("Content-Type", "application/json"); 41 | headers.put("Authorization", "Bearer " + token); 42 | 43 | ObjectMapper objectMapper = new ObjectMapper(); 44 | 45 | Path p = new File("README.md").toPath(); 46 | String desc = Files.readString(p); 47 | 48 | Map map = new HashMap<>(); 49 | map.put("description", desc); 50 | String payload = new ObjectMapper().writeValueAsString(map); 51 | 52 | JsonNode jsonNode = objectMapper.readTree(payload); 53 | 54 | String resp = Requests.put("https://quay.io/api/v1/repository/jbangdev/jbang-action") 55 | .headers(headers) 56 | .jsonBody(jsonNode) 57 | .send().readToText(); 58 | 59 | System.out.println(resp); 60 | return 0; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /.github/workflows/verify.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: verify-githubaction 4 | 5 | on: 6 | workflow_dispatch: 7 | schedule: 8 | - cron: '* */8 * * *' 9 | 10 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 11 | jobs: 12 | check: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: properties@jbangdev from latest release 17 | uses: jbangdev/jbang-action@v0.86.0 18 | with: 19 | script: properties@jbangdev 20 | - name: properties@jbangdev from main 21 | uses: jbangdev/jbang-action@main 22 | with: 23 | script: properties@jbangdev 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .secrets 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM eclipse-temurin:11 2 | 3 | LABEL "org.opencontainers.image.title"="jbang-action" 4 | LABEL "org.opencontainers.image.description"="Unleash the power of Java" 5 | LABEL "org.opencontainers.image.url"="https://jbang.dev" 6 | LABEL "org.opencontainers.image.licenses"="MIT" 7 | LABEL "org.opencontainers.image.version"="0.132.1" 8 | LABEL "org.opencontainers.image.revision"="27cdd5f7641876e6760806a173bbaf37976d034b" 9 | LABEL org.opencontainers.image.source=https://github.com/jbangdev/jbang-action 10 | 11 | 12 | COPY assembly/* / 13 | 14 | ## mkdir of .userPrefs is to fix https://github.com/jbangdev/jbang/issues/1831 15 | RUN jar xf jbang-0.132.1.zip && \ 16 | rm jbang-0.132.1.zip && \ 17 | mv jbang-* jbang && \ 18 | chmod +x jbang/bin/jbang && \ 19 | mkdir -p $HOME/.java/.userPrefs 20 | 21 | 22 | ENV PATH="${PATH}:/jbang/bin" 23 | 24 | ADD ./entrypoint /bin/entrypoint 25 | 26 | ENV SCRIPTS_HOME=/scripts 27 | ENV JBANG_VERSION=0.132.1 28 | ENV JBANG_PATH=/jbang/bin 29 | 30 | VOLUME /scripts 31 | 32 | ENV PATH="${PATH}:/jbang/bin" 33 | 34 | ## github action does not allow writing to $HOME thus routing this elsewhere 35 | ENV JBANG_DIR="/jbang/.jbang" 36 | 37 | ENTRYPOINT ["entrypoint"] 38 | -------------------------------------------------------------------------------- /Dockerfile-remote: -------------------------------------------------------------------------------- 1 | FROM adoptopenjdk:11-jdk-hotspot 2 | 3 | LABEL "org.opencontainers.image.title"="jbang" 4 | LABEL "org.opencontainers.image.description"="Unleash the power of Java" 5 | LABEL "org.opencontainers.image.url"="https://jbang.dev" 6 | LABEL "org.opencontainers.image.licenses"="MIT" 7 | LABEL "org.opencontainers.image.version"="0.106.1" 8 | LABEL "org.opencontainers.image.revision"="8516294243004f4c0286ae578cbe964c76f5fce3" 9 | 10 | 11 | RUN curl -Ls "https://github.com/jbangdev/jbang/releases/download/v0.106.1/jbang-0.106.1.zip" --output jbang-0.106.1.zip && \ 12 | unzip jbang-0.106.1.zip && \ 13 | rm jbang-0.106.1.zip && \ 14 | chmod +x jbang-0.106.1/bin/jbang 15 | 16 | VOLUME /scripts 17 | 18 | ENV PATH="${PATH}:/jbang-0.106.1/bin" 19 | 20 | ENTRYPOINT ["/jbang-0.106.1/bin/jbang"] 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Max Rydahl Andersen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JBang Container for Docker and Github Action 2 | 3 | [![GitHub release badge](https://badgen.net/github/release/jbangdev/jbang-action/stable)](https://github.com/jbangdev/jbang-action/releases/latest) 4 | [![GitHub license badge](https://badgen.net/github/license/jbangdev/jbang-action)]() 5 | [![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=) 6 | [![DockerHub Pulls](https://img.shields.io/docker/pulls/jbangdev/jbang-action)]() 7 | 8 | This container intended for quick and easily run java based scripts with [jbang](https://jbang.dev). 9 | 10 | Can be used directly with docker or as a GitHub Action. 11 | 12 | The source is located in [jbangdev/jbang](https://github.com/jbangdev/jbang/blob/HEAD/src/jreleaser/distributions/jbang-action/docker/) and are updated in this repo on every tag/release of jbangdev/jbang. 13 | 14 | 15 | [Source](https://github.com/jbangdev/jbang-action) 16 | 17 | ## Container/Docker usage 18 | 19 | Using dockerhub images: 20 | 21 | ``` 22 | docker run -v `pwd`:/ws --workdir=/ws jbangdev/jbang-action helloworld.java 23 | ``` 24 | 25 | Using quay.io images: 26 | 27 | ``` 28 | docker run -v `pwd`:/ws --workdir=/ws quay.io/jbangdev/jbang-action helloworld.java 29 | ``` 30 | 31 | 32 | ## Github Action 33 | 34 | ### Inputs 35 | 36 | Key | Example | Description 37 | ----|---------|------------ 38 | trust | `https://github.com/maxandersen` | Host pattern to add to be trusted before the script are executed. 39 | jbangargs | `--verbose` | Arguments to pass to jbang before the script. 40 | script | `hello.java` | File, URL or alias referring to script to run 41 | 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. 42 | 43 | ### Outputs 44 | 45 | ### Example usage 46 | 47 | Here it is assumed you have a jbang script called `createissue.java` in the root of your project. 48 | 49 | ```yaml 50 | on: [push] 51 | 52 | jobs: 53 | jbang: 54 | runs-on: ubuntu-latest 55 | name: A job to run jbang 56 | steps: 57 | - name: checkout 58 | uses: actions/checkout@v1 59 | - uses: actions/cache@v1 60 | with: 61 | path: /root/.jbang 62 | key: $-jbang-$ 63 | restore-keys: | 64 | $-jbang- 65 | - name: jbang 66 | uses: jbangdev/jbang-action@v0.132.1 67 | with: 68 | script: createissue.java 69 | scriptargs: "my world" 70 | env: 71 | JBANG_REPO: /root/.jbang/repository 72 | GITHUB_TOKEN: $ 73 | ``` 74 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Java Scripting w/jbang' 2 | description: 'Run Java as scripts with https://jbang.dev from your GitHub repo' 3 | branding: 4 | icon: hash 5 | color: red 6 | inputs: 7 | jbangargs: 8 | description: 'Arguments for jbang' 9 | required: false 10 | script: 11 | description: 'Script file to run' 12 | required: true 13 | scriptargs: 14 | description: 'arguments to pass on to the script' 15 | required: false 16 | trust: 17 | description: "if present will be added to trust before running jbang" 18 | required: false 19 | runs: 20 | using: 'docker' 21 | image: 'docker://ghcr.io/jbangdev/jbang-action:0.132.1' 22 | -------------------------------------------------------------------------------- /assembly/jbang-0.132.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbangdev/jbang-action/b924849ade11dbfc3aace8da1c598a84fb3ddfbc/assembly/jbang-0.132.1.zip -------------------------------------------------------------------------------- /container-structure-test.yaml: -------------------------------------------------------------------------------- 1 | schemaVersion: "2.0.0" 2 | 3 | # check that jbang is in the correct location 4 | fileExistenceTests: 5 | - name: "jbang installation" 6 | path: '/jbang/bin/jbang' 7 | shouldExist: true 8 | 9 | commandTests: 10 | - name: "does basic jbang work" 11 | command: "/jbang/bin/jbang" 12 | expectedError: 13 | - "jbang is a tool for building and running" 14 | - "Usage:" 15 | - name: "JBANG_VERSION has a version number" 16 | command: "echo" 17 | args: ["jb $JBANG_VERSION"] 18 | expectedOutput: ["jb \\d+.\\d+\\d+"] 19 | - name: "hello world via url" 20 | command: "entrypoint" 21 | args: 22 | - "https://github.com/jbangdev/jbang/blob/HEAD/itests/helloworld.java" 23 | expectedOutput: 24 | - "Hello World" 25 | - name: "Does trust work" 26 | envVars: 27 | - key: INPUT_TRUST 28 | value: https://github.com/jruby 29 | command: "entrypoint" 30 | expectedError: 31 | - ".*(Trusting permanently:).*" 32 | - ".*(https://github.com/jruby).*" 33 | - name: "Does multiple arguments work" 34 | envVars: 35 | - key: INPUT_SCRIPT 36 | value: hello@jbangdev 37 | - key: INPUT_SCRIPTARGS 38 | value: Hello There 39 | command: "entrypoint" 40 | expectedOutput: 41 | - "Hello Hello" 42 | - "Hello There" 43 | -------------------------------------------------------------------------------- /entrypoint: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # In OpenShift, containers are run as a random high number uid 4 | # that doesn't exist in /etc/passwd 5 | if [ `id -u` -ge 500 ] || [ -z "${CURRENT_UID}" ]; then 6 | 7 | cat << EOF > /tmp/passwd 8 | root:x:0:0:root:/root:/bin/bash 9 | jbang:x:`id -u`:`id -g`:,,,:/scripts:/bin/bash 10 | EOF 11 | 12 | cat /tmp/passwd > /etc/passwd 13 | rm /tmp/passwd 14 | fi 15 | 16 | if [[ ! -z "$INPUT_TRUST" ]]; then 17 | $JBANG_PATH/jbang trust add $INPUT_TRUST 18 | fi 19 | 20 | echo jbang $INPUT_JBANGARGS $INPUT_SCRIPT $INPUT_ARGS "${@}" 21 | exec $JBANG_PATH/jbang $INPUT_JBANGARGS $INPUT_SCRIPT $INPUT_SCRIPTARGS "${@}" 22 | --------------------------------------------------------------------------------