Luarocks repository in JFrog Artifactory

Jfrog Artifactory does not support Luarocks repository layout yet. This repository adds a workaround to store luarocks in Artifactory.

It comes in handy if:

  • you create Lua modules (rocks)
  • you can't store them at luarocks.org public repo
  • you have an Artifactory instance

Replicating Luarocks server

Luarocks is a static HTTP server with index and manifest files. It's easy to replicate its functions using an Artifactory repository with generic layout.

To create or update Luarocks index and manifests, you need to do the following:

  1. Create a new repository in Artifactory (for example, myluarocks.snapshot).
  2. Upload a rock to this repository (manually or via API).
  3. Connect to myluarocks.snapshot via WebDav.
  4. Create index and manifest with luarock-admin make-manifest myluarocks.snapshot.
  5. Wait until Artifactory reindexes the storage (5-15 seconds).

Now you can use myluarocks.snapshot as a Luarocks server:

luarocks install --server=http://repo.example.com/artifactory/myluarocks.snapshot mypackage

Note: Our script forces no-dependencies mode for the sake of testing.

If you compile and upload all dependencies to myluarocks.snapshot, use --only-server:

luarocks install --only-server=http://repo.example.com/artifactory/myluarocks.snapshot mypackage

Automation

This repository provides a shell script and a Dockerfile to update server manifests and test package installation.

Installation

We recommend using Docker to keep things isolated and leave your environment untouched.

  • Install Docker

  • Create an Artifactory repo

  • Deploy a rock for testing

    Important: If your artifactory repo does not allow anonymous read access, add authentication by modifying curl launch parameters:

    echo "variables = {CURL = \"curl -H 'Authorization: Basic $BASE64_AUTH'\"}" > ~/.luarocks/config-${LUA_VERSION%.*}.lua

    OR (only with Luarocks 3.1+):

    luarocks config CURL="curl -H 'Authorization: Basic $BASE64_AUTH'"
  • Use this repo to create Luarocks manifests:

git clone https://gitlab.com/devopshq/luarocks-artifactory.git
cd luarocks-artifactory
docker build -t luarocks-artifactory .
docker run --rm --device /dev/fuse -v "$(pwd)/create-luarocks.sh:/create-luarocks.sh" --privileged luarocks-artifactory sh /create-luarocks.sh http://repo.example.com/artifactory myluarocks.snapshot username:password
luarocks  install --server=http://repo.example.com/artifactory/myluarocks.snapshot mypackage

Important: Use USER=root. See GitHub issue.

Usage

> sh ./create-luarocks.sh --help

Usage:
    create-luarocks.sh ARTIFACTORY_URL REPO USERNAME:PASSWORD [--install-any pkg1 pgk2] [--install-all pkg1 pgk2]
    ARTIFACTORY_URL             URL to Artifactory instance, e.g: https://repo.example.com/artifactory.
    REPOSITORY                  Repository to store rocks and maintain index and manifest.
    USERNAME:PASSWORD           Credentials for user with read, write and remove permissions to this repository (split by colon).
    --install-all pkg1 pgk2     (optional) Try to install all specified packages.
    --install-any pkg1 pgk2     (optional) Try to install any of specified packages.

Examples:
    create-luarocks.sh https://repo.example.com/artifactory myluarocks.snapshot deploy_user:password
    create-luarocks.sh https://repo.example.com/artifactory myluarocks.snapshot deploy_user:password --install-any penlight rapidjson

See GitLab CI example.

Scheduler and automation

You can schedule or use Artifactory WebHook to automate indexing.