diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0899727e..f9d4c746 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,3 +32,16 @@ jobs: rockspecs: ${{ needs.affected.outputs.rockspecs }} secrets: apikey: ${{ secrets.LUAROCKS_APIKEY }} + + docker: + if: >- + ${{ + github.repository == 'lunarmodules/busted' && + ( github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/') ) + }} + uses: lunarmodules/.github/.github/workflows/docker_ghcr_deploy.yml@main + with: + username: ${{ github.actor }} + tag: ${{ github.ref_name }} + secrets: + token: ${{ secrets.GHCR_PAT }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..ca458920 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +#syntax=docker/dockerfile:1.2 + +FROM akorn/luarocks:lua5.4-alpine AS builder + +RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \ + dumb-init gcc libc-dev + +COPY ./ /src +WORKDIR /src + +RUN luarocks --tree /pkgdir/usr/local make +RUN find /pkgdir -type f -exec sed -i -e 's!/pkgdir!!g' {} \; + +FROM akorn/luarocks:lua5.4-alpine AS final + +RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \ + dumb-init + +LABEL org.opencontainers.image.title="Busted" +LABEL org.opencontainers.image.description="A containerized version of Busted, a unit testing framework for Lua." +LABEL org.opencontainers.image.authors="Caleb Maclennan " +LABEL org.opencontainers.image.licenses="MIT" +LABEL org.opencontainers.image.url="https://github.com/lunarmodules/busted/pkgs/container/busted" +LABEL org.opencontainers.image.source="https://github.com/lunarmodules/busted" + +COPY --from=builder /pkgdir / +RUN busted --version + +WORKDIR /data + +ENTRYPOINT ["busted", "--verbose"] diff --git a/README.md b/README.md index 1c72287e..0773dd78 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,79 @@ luarocks make busted spec ``` +Docker +------ + +Alternatively Busted can be run as a standalone docker container. +This approach is somewhat limited because many projects will require extra dependencies which will need to be installed inside the Docker container. +Luarocks is provided in the container so many dependencies can be added. +The images are based on Alpine Linux so you can also use `apk add` to install system dependencies if needed. +The Docker use case is probably most advantageous for pure-Lua projects with no dependencies: i.g. small libraries not large apps. + +The usage of docker is fairly simple. +You can either build your own or download a prebuilt version. +To build your own, execute the following command from the source directory of this project: + +```console +$ docker build -t ghcr.io/lunarmodules/busted:HEAD . +``` + +To use a prebuilt one, download it from the GitHub Container Registry. +Here we use the one tagged *latest*, but you can substitute *latest* for any tagged release. + +```console +$ docker pull ghcr.io/lunarmodules/busted:latest +``` + +Once you have a container you can run it on one file or a source tree (substitute *latest* with *HEAD* if you built your own or with the tagged version you want if applicable): + +```console +# Run on an entire project +$ docker run -v "$(pwd):/data" ghcr.io/lunarmodules/busted:latest + +# Run on one directory: +$ docker run -v "$(pwd):/data" ghcr.io/lunarmodules/busted:latest specs +``` + +A less verbose way to run it in most shells is with at alias: + +```console +# In a shell or in your shell's RC file: +$ alias busted='docker run -v "$(pwd):/data" ghcr.io/lunarmodules/busted:latest' + +# Thereafter just run: +$ busted +``` +### Use as a CI job + +There are actually many ways to run Busted remotely as part of a CI work flow. +Because packages are available for many platforms, one way would be to just use your platforms native package installation system to pull them into whatever CI runner environment you already use. +Another way is to pull in the prebuilt Docker container and run that. + +As a case study, here is how a workflow could be setup in GitHub Actions: + +```yaml +name: Busted +on: [push, pull_request] +jobs: + sile: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Run Busted + uses: lunarmodules/busted@v0 +``` + +By default the GH Action is configured to run `busted --verbose`, but you can also pass it your own `args` to replace the default input of `.`. + +```yaml + - name: Run Busted + uses: lunarmodules/busted@v0 + with: + args: --tags=MYTAGS +``` + License ------- diff --git a/action.yml b/action.yml new file mode 100644 index 00000000..f5487aa4 --- /dev/null +++ b/action.yml @@ -0,0 +1,17 @@ +name: Busted +description: Busted +inputs: + args: + description: Arguments passed to busted + required: false + default: "." +runs: + using: docker + image: docker://ghcr.io/lunarmodules/busted:v2.0.0 + entrypoint: sh + args: + - -c + - busted ${{ inputs.args }} +branding: + icon: check + color: yellow