diff --git a/.github/workflows/publish-feature.yml b/.github/workflows/publish-feature.yml new file mode 100644 index 0000000..8ac73c0 --- /dev/null +++ b/.github/workflows/publish-feature.yml @@ -0,0 +1,34 @@ +name: Publish Devcontainer Feature + +on: + release: + types: [created] + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Install Devcontainer CLI + run: npm install -g @devcontainers/cli + + - name: Login to GitHub Container Registry + run: echo "${{ secrets.WRITE_PACKAGES_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Add version to environment + run: | + VERSION="${{ github.ref_name }}" + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Add version to devcontainer-feature.json + run: | + jq --arg VERSION "${{ env.VERSION }}" '.version = $VERSION' src/cvmfs/devcontainer-feature.json > tmp.json + mv tmp.json src/cvmfs/devcontainer-feature.json + + - name: Publish Devcontainer Feature + run: devcontainer features publish --namespace ${{ github.actor }}/${{ github.repository }} . + + - name: Build Devcontainer Feature + run: devcontainer build --workspace-folder . --image-name test-cvmfs-feature --additional-features ghcr.io/${{ github.actor }}/${{ github.repository }}/cvmfs:${{ env.VERSION }} diff --git a/README.devcontainer-feature.md b/README.devcontainer-feature.md new file mode 100644 index 0000000..4d425a2 --- /dev/null +++ b/README.devcontainer-feature.md @@ -0,0 +1,39 @@ +# CVMFS Devcontainer Feature + +This directory contains a devcontainer feature for installing and configuring the CVMFS client. The definition is located in the top-level directory to allow reuse of the GitHub Actions scripts. + +## Publishing to GHCR + +This feature is intended to be published to the GitHub Container Registry (GHCR) to be easily reusable by other projects. + +### Manual Publishing + +1. **Install the Devcontainer CLI:** + ```bash + npm install -g @devcontainers/cli + ``` + +2. **Create a Personal Access Token (PAT):** + * Go to GitHub **Settings** > **Developer settings** > **Personal access tokens** > **Tokens (classic)**. + * Generate a new token with the `write:packages` scope. + * Export the token as an environment variable: + ```bash + export WRITE_PACKAGES_TOKEN=your-personal-access-token + ``` + +3. **Log in to GHCR:** + ```bash + echo $WRITE_PACKAGES_TOKEN | docker login ghcr.io -u your-github-username --password-stdin + ``` + +4. **Publish the Feature:** + Run the following command from the root of this repository. The namespace should match the GitHub organization (`cvmfs-contrib`). + ```bash + devcontainer features publish --namespace cvmfs-contrib/github-action-cvmfs . + ``` + +### Automated Publishing + +This repository is configured with a GitHub Actions workflow to automate this process. When a new release is published on GitHub, the workflow will automatically build and publish the feature to GHCR. + +For this to work, the `WRITE_PACKAGES_TOKEN` secret (a Personal Access Token with `write:packages` scope) must be configured in the repository's **Settings > Secrets and variables > Actions**. diff --git a/README.md b/README.md index c2c5fad..5c0ba4f 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,23 @@ This GitHub Action is only expected to work in workflows that [run on](https://d `windows` targets are not supported. +## Devcontainer Usage + +This repository provide a Dev Container Feature to enable CernVM-FS in your Dev Containers. To use it, open this repository in a devcontainer-compatible editor like VS Code with the Dev Containers extension. + +For example, you can add the following to your `devcontainer.json` to use this feature: +```json +{ + "name": "CVMFS Action Dev", + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "ghcr.io/cvmfs-contrib/github-action-cvmfs/cvmfs": { + "CVMFS_REPOSITORIES": "sft.cern.ch" + } + } +} +``` + ## Use With Docker In case your workflow uses docker containers, the cvmfs directory can be mounted inside the container by using the flag `-v /cvmfs:/cvmfs:shared`. diff --git a/devcontainer-feature.json b/devcontainer-feature.json new file mode 100644 index 0000000..84d7baf --- /dev/null +++ b/devcontainer-feature.json @@ -0,0 +1,24 @@ +{ + "name": "CVMFS", + "id": "cvmfs", + "version": "0.0.0", + "description": "Installs CVMFS client", + "options": { + "CVMFS_REPOSITORIES": { + "type": "string", + "default": "sft.cern.ch", + "description": "Comma-separated list of fully qualified repository names that shall be mountable under /cvmfs" + }, + "CVMFS_CONFIG_PACKAGE": { + "type": "string", + "default": "cvmfs-config-default", + "description": "URL to the cvmfs config package to install" + }, + "CVMFS_HTTP_PROXY": { + "type": "string", + "default": "DIRECT", + "description": "Chain of HTTP proxy groups used by CernVM-FS. Defaults to DIRECT." + } + }, + "entrypoint": "install-cvmfs-linux.sh" +} diff --git a/setup-cvmfs.sh b/setup-cvmfs.sh index 8389158..86cffff 100755 --- a/setup-cvmfs.sh +++ b/setup-cvmfs.sh @@ -77,7 +77,16 @@ fi echo "::endgroup::" -if [ "$(uname)" == "Darwin" ]; then +if [ "$(uname)" == "Linux" ]; then + # Mount CVMFS repositories (in case no autofs) + for repo in $(echo ${CVMFS_REPOSITORIES} | sed "s/,/ /g") + do + if [ ! -d /cvmfs/${repo} ]; then + sudo mount -t cvmfs ${repo} /cvmfs/${repo} + fi + done +elif [ "$(uname)" == "Darwin" ]; then + # Mount CVMFS repositories (no autofs available) for repo in $(echo ${CVMFS_REPOSITORIES} | sed "s/,/ /g") do mkdir -p /Users/Shared/cvmfs/${repo}