Skip to content
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

Add xdg-utils package to shopify-cli feature install script #92

Merged
merged 3 commits into from
Jan 16, 2025

Conversation

SimonShirley
Copy link

Shopify CLI has a dependency on xdg-open (as part of xdg-utils) in order to authenticate.

After inspecting the nanolayer source code, I discovered that it had an install command that can install apt-get and apk packages.

This pull request will install xdg-utils in the setup process.

I've opted for using the apt-get and apk check from library_scripts.sh rather than using the ghcr.io/devcontainers-extra/features/apt-get-packages feature because I don't want to create a limitation on apt-get.

See related issues:

I created a test scenario locally, adapted from the scenario already committed from the author of the feature, but haven't included it in this commit because it requires a parameter value that could be deemed as personal info. It doesn't appear that Shopify has a public development store to run this against - or if there is, I couldn't find one.

The check needed would have been:
check "shopify theme list" shopify theme list --store your_store_name

@SimonShirley SimonShirley changed the title Add xdg-utils to install script with apt-get and apk Add xdg-utils shopify-cli feature install script Jan 16, 2025
@SimonShirley SimonShirley changed the title Add xdg-utils shopify-cli feature install script Add xdg-utils package to shopify-cli feature install script Jan 16, 2025
@SimonShirley
Copy link
Author

Would I need to bump the version number in devcontainer-feature.json to 1.0.3?

@koralowiec koralowiec self-requested a review January 16, 2025 17:03
@koralowiec
Copy link
Member

Yeah, please bump the version to 1.0.3

@SimonShirley
Copy link
Author

That's now done 👍

Copy link
Member

@koralowiec koralowiec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine. Indeed it seems that we cannot test it without having a store for that, so we can skip adding a test scenario

However, could you please add a test scenario with mcr.microsoft.com/devcontainers/base:alpine as the base image?

So something like this to scenarios.json:

    "test_alpine": {
        "image": "mcr.microsoft.com/devcontainers/base:alpine",
        "features": {
            "shopify-cli": {}
        }
    }

And test_alpine.sh:

#!/usr/bin/env bash

set -e

source dev-container-features-test-lib

check "shopify --version" shopify --version

reportResults

@koralowiec koralowiec added the existing feature This PR or issue is about modifying an existing Dev Container feature label Jan 16, 2025
@SimonShirley
Copy link
Author

Just as a quick update, the test_alpine scenario is failing, so I'll take a look into it.

On first glance, it looks like nanolayer is trying to call apt-get, which Alpine can't do:

vscode ➜ /workspaces/devcontainer-features (main) $ just test-scenario shopify-cli test_alpine
devcontainer features test -f shopify-cli --filter "test_alpine" --skip-autogenerated

┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐
|    Dev Container Features   |   
│           v0.72.0           │
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘

>  baseImage:         ubuntu:focal
>  Target Folder:     /workspaces/devcontainer-features
>  features:          shopify-cli

🏃 Starting test(s)...

🧪 Starting 'shopify-cli' tests...
🧪 Executing scenarios for feature 'shopify-cli'...
>  Running scenario:  test_alpine

📝 Scenario generated: {
  "image": "mcr.microsoft.com/devcontainers/base:alpine",
  "features": {
    "./shopify-cli": {}
  }
}
>  workspaceFolder:   /tmp/devcontainercli/container-features-test/1737048529690

⏳ Building test container...

[9 ms] @devcontainers/cli 0.72.0. Node.js v22.13.0. linux 6.10.14-linuxkit x64.
[1222 ms] Resolving Feature dependencies for './shopify-cli'...
[2316 ms] Soft-dependency 'ghcr.io/devcontainers/features/node' is not required.  Removing from installation order...
[2316 ms] Soft-dependency 'ghcr.io/devcontainers-extra/features/npm-package' is not required.  Removing from installation order...
[2398 ms] Start: Run: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-vscode/container-features/0.72.0-1737048531254 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/base:alpine --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -f /tmp/devcontainercli-vscode/container-features/0.72.0-1737048531254/Dockerfile.extended -t vsc-1737048529690-b7be8ae9ba5edb9ccec70d51fd988e65e72ccdf6c5657cb4dc405fdcfc97ca6f-features /tmp/devcontainercli-vscode/empty-folder
[+] Building 20.0s (14/14) FINISHED                                                                                                                                                             docker:default
 => [internal] load build definition from Dockerfile.extended                                                                                                                                             0.0s
 => => transferring dockerfile: 1.79kB                                                                                                                                                                    0.0s
 => resolve image config for docker-image://docker.io/docker/dockerfile:1.4                                                                                                                               1.4s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531bd80fb0a858632727cf7a112fbfd19b17e94c4e84ced81e24ef1a0dbc                                                                         0.0s
 => [internal] load .dockerignore                                                                                                                                                                         0.0s
 => => transferring context: 2B                                                                                                                                                                           0.0s
 => [internal] load metadata for mcr.microsoft.com/devcontainers/base:alpine                                                                                                                              0.2s
 => [context dev_containers_feature_content_source] load .dockerignore                                                                                                                                    0.1s
 => => transferring dev_containers_feature_content_source: 2B                                                                                                                                             0.0s
 => [context dev_containers_feature_content_source] load from client                                                                                                                                      0.0s
 => => transferring dev_containers_feature_content_source: 11.43kB                                                                                                                                        0.0s
 => [dev_containers_feature_content_normalize 1/3] FROM mcr.microsoft.com/devcontainers/base:alpine@sha256:5212d8ed44c89bfadad14a03104ef75b09c5de8642a58721c271f2e9155f5023                               0.0s
 => CACHED [dev_containers_target_stage 2/5] RUN mkdir -p /tmp/dev-container-features                                                                                                                     0.0s
 => CACHED [dev_containers_feature_content_normalize 2/3] COPY --from=dev_containers_feature_content_source devcontainer-features.builtin.env /tmp/build-features/                                        0.0s
 => CACHED [dev_containers_feature_content_normalize 3/3] RUN chmod -R 0755 /tmp/build-features/                                                                                                          0.0s
 => CACHED [dev_containers_target_stage 3/5] COPY --from=dev_containers_feature_content_normalize /tmp/build-features/ /tmp/dev-container-features                                                        0.0s
 => CACHED [dev_containers_target_stage 4/5] RUN echo "_CONTAINER_USER_HOME=$( (command -v getent >/dev/null 2>&1 && getent passwd 'root' || grep -E '^root|^[^:]*:[^:]*:root:' /etc/passwd || true) | c  0.0s
 => ERROR [dev_containers_target_stage 5/5] RUN --mount=type=bind,from=dev_containers_feature_content_source,source=shopify-cli_0,target=/tmp/build-features-src/shopify-cli_0     cp -ar /tmp/build-fe  18.0s
------                                                                                                                                                                                                         
 > [dev_containers_target_stage 5/5] RUN --mount=type=bind,from=dev_containers_feature_content_source,source=shopify-cli_0,target=/tmp/build-features-src/shopify-cli_0     cp -ar /tmp/build-features-src/shopify-cli_0 /tmp/dev-container-features  && chmod -R 0755 /tmp/dev-container-features/shopify-cli_0  && cd /tmp/dev-container-features/shopify-cli_0  && chmod +x ./devcontainer-features-install.sh  && ./devcontainer-features-install.sh  && rm -rf /tmp/dev-container-features/shopify-cli_0:                                                                                                                               
0.265 ===========================================================================                                                                                                                              
0.265 Feature       : Shopify CLI (via npm)                                                                                                                                                                    
0.265 Description   : Shopify CLI is a command-line interface tool that helps you build Shopify apps and themes. It quickly generates Shopify apps, themes, and custom storefronts. You can also use it to automate many common development tasks.
0.265 Id            : Unknown
0.265 Version       : 1.0.3
0.265 Documentation : http://github.com/devcontainers-extra/features/tree/main/src/shopify-cli
0.265 Options       :
0.265     VERSION="latest"
0.265 ===========================================================================
7.090 nanolayer
9.708 hoii
9.804 cp -p -R /var/cache/apk /tmp/tmpgp5ikxgd
9.804 apk update
9.804 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/x86_64/APKINDEX.tar.gz
10.15 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/community/x86_64/APKINDEX.tar.gz
11.49 v3.20.5-16-g366d4f2813b [https://dl-cdn.alpinelinux.org/alpine/v3.20/main]
11.49 v3.20.5-12-gd1bff4aa572 [https://dl-cdn.alpinelinux.org/alpine/v3.20/community]
11.49 OK: 24178 distinct packages available
11.75 apk add --no-cache xdg-utils
11.75 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/x86_64/APKINDEX.tar.gz
12.05 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/community/x86_64/APKINDEX.tar.gz
13.17 (1/11) Installing libmagic (5.45-r1)
13.17 (2/11) Installing file (5.45-r1)
13.32 (3/11) Installing xprop (1.2.7-r0)
13.34 (4/11) Installing libxext (1.3.6-r2)
13.36 (5/11) Installing libice (1.1.1-r6)
13.38 (6/11) Installing libuuid (2.40.1-r1)
13.40 (7/11) Installing libsm (1.2.4-r4)
13.41 (8/11) Installing libxt (1.3.0-r5)
13.43 (9/11) Installing libxmu (1.1.4-r2)
13.49 (10/11) Installing xset (1.2.5-r1)
13.52 (11/11) Installing xdg-utils (1.2.1-r0)
13.54 Executing busybox-1.36.1-r29.trigger
13.60 OK: 537 MiB in 204 packages
13.81 rm -r /var/cache/apk && mv /tmp/tmpgp5ikxgd/apk /var/cache/apk
17.22 cd /tmp/tmpq49ebat0 && chmod +x -R . && _REMOTE_USER="vscode" _REMOTE_USER_HOME="/home/vscode" PACKAGE="@shopify/cli" VERSION="latest" NANOLAYER_VERBOSE="" NANOLAYER_FORCE_CLI_INSTALLATION="" NANOLAYER_PROPAGATE_CLI_LOCATION="1" NANOLAYER_CLI_LOCATION="/tmp/nanolayer-goBjtP0auz/nanolayer" bash  -i  +H ./install.sh
17.22 Installing node and npm...
17.23 find: /var/lib/apt/lists/*: No such file or directory
17.23 Running apt-get update...
17.23 bash: apt-get: command not found
17.34 Traceback (most recent call last):
17.34   File "<string>", line 1, in <module>
17.34   File "nanolayer.__main__", line 50, in main
17.34   File "typer.main", line 328, in __call__
17.34   File "typer.main", line 311, in __call__
17.34   File "click.core", line 1157, in __call__
17.34   File "typer.core", line 778, in main
17.34   File "typer.core", line 216, in _main
17.34   File "click.core", line 1688, in invoke
17.34   File "click.core", line 1688, in invoke
17.34   File "click.core", line 1434, in invoke
17.34   File "click.core", line 783, in invoke
17.34   File "typer.main", line 683, in wrapper
17.34   File "nanolayer.cli.install", line 66, in install_devcontainer_feature
17.34   File "nanolayer.installers.devcontainer_feature.oci_feature_installer", line 134, in install
17.34   File "nanolayer.utils.invoker", line 59, in invoke
17.35 nanolayer.utils.invoker.Invoker.InvokerException: The command 'cd /tmp/tmpq49ebat0 && chmod +x -R . && _REMOTE_USER="vscode" _REMOTE_USER_HOME="/home/vscode" PACKAGE="@shopify/cli" VERSION="latest" NANOLAYER_VERBOSE="" NANOLAYER_FORCE_CLI_INSTALLATION="" NANOLAYER_PROPAGATE_CLI_LOCATION="1" NANOLAYER_CLI_LOCATION="/tmp/nanolayer-goBjtP0auz/nanolayer" bash  -i  +H ./install.sh' failed. error: Return Code: 127. see logs for details.
17.64 ERROR: Feature "Shopify CLI (via npm)" (Unknown) failed to install! Look at the documentation at http://github.com/devcontainers-extra/features/tree/main/src/shopify-cli for help troubleshooting this error.
------
ERROR: failed to solve: process "/bin/sh -c cp -ar /tmp/build-features-src/shopify-cli_0 /tmp/dev-container-features  && chmod -R 0755 /tmp/dev-container-features/shopify-cli_0  && cd /tmp/dev-container-features/shopify-cli_0  && chmod +x ./devcontainer-features-install.sh  && ./devcontainer-features-install.sh  && rm -rf /tmp/dev-container-features/shopify-cli_0" did not complete successfully: exit code: 1
[-] Failed to launch container:

Command failed: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-vscode/container-features/0.72.0-1737048531254 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/base:alpine --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -f /tmp/devcontainercli-vscode/container-features/0.72.0-1737048531254/Dockerfile.extended -t vsc-1737048529690-b7be8ae9ba5edb9ccec70d51fd988e65e72ccdf6c5657cb4dc405fdcfc97ca6f-features /tmp/devcontainercli-vscode/empty-folder
error: Recipe `test-scenario` failed on line 7 with exit code 1

@koralowiec
Copy link
Member

It seems that the problem isn't your change, but the npm-package itself (which is used in the rest of the script):

$nanolayer_location \
    install \
    devcontainer-feature \
    "ghcr.io/devcontainers-extra/features/npm-package:1.0.3" \
    --option package='@shopify/cli' --option version="$VERSION"

$nanolayer_location \
    install \
    devcontainer-feature \
    "ghcr.io/devcontainers-extra/features/npm-package:1.0.3" \
    --option package='@shopify/theme' --option version="$VERSION"

https://github.com/devcontainers-extra/features/blob/main/src/npm-package/install.sh - It doesn't support Alpine Linux

I think that in this case we should get rid of this elif:

elif [ -x "/sbin/apk" ] ; then
    $nanolayer_location \
        install \
        apk \
        "xdg-utils"

Let's keep only apt support there (so no test scenario for Alpine needed, please just remove the apk part from install script)

Copy link
Member

@koralowiec koralowiec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated request change

src/shopify-cli/install.sh Outdated Show resolved Hide resolved
@SimonShirley
Copy link
Author

Thanks for taking a look! I was coming to a similar conclusion with the npm-package ☺️

Currently, the npm-package feature doesn't support Alpine, so this check has been removed for now.
@SimonShirley
Copy link
Author

That's now removed 👍

@SimonShirley
Copy link
Author

I use Shopify (hence the need for the feature!) so can post the test results of a scenario using one of our stores, if that will help.

@koralowiec
Copy link
Member

No need for that, based on the issue you linked installing xdg-utils fixes the problem, so that's fine

Copy link
Member

@koralowiec koralowiec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@koralowiec koralowiec merged commit 906eb31 into devcontainers-extra:main Jan 16, 2025
4 checks passed
@koralowiec
Copy link
Member

FYI: The updated feature will be available once the Release workflow deploys it

@SimonShirley
Copy link
Author

I can confirm that with the inclusion of this feature in release, that it works as intended :)

Thanks again!

@koralowiec
Copy link
Member

Great to hear, thanks for providing the fix in your PR! 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
existing feature This PR or issue is about modifying an existing Dev Container feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants