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

Feat: Avd install for codespaces #3476

Merged
merged 3 commits into from
Jan 16, 2024

Conversation

ankudinov
Copy link
Contributor

@ankudinov ankudinov commented Jan 9, 2024

Change Summary

This PR add support for AVD installation inside Codespaces.
Currently mount fails due to: https://github.com/orgs/community/discussions/85658
As a workaround, dev image entrypoint.sh will get additional logic to install AVD directly from the workspace.

Component(s) name

containers

How to test

Once AVD dev image will be re-build after merge, start Github Codespace on any PR and check:

  • ansible --version
  • ansible-galaxy collection list

It should be also possible to "unpack" AVD examples and build configs in every example directory.

@ankudinov
Copy link
Contributor Author

Due to the comments, entrypoint.sh was changed significantly and requires full testing.
Please proceed with the following steps to prepare local dev container build:

  • clone AVD repository

  • create a new branch for testing purposes only (it can be deleted once testing is finished)

  • add following files to .devcontainer/ directory:

    • Dockerfile

      ARG FROM_IMAGE
      ARG FROM_VARIANT
      
      FROM ${FROM_IMAGE}:${FROM_VARIANT}
      
      ARG USERNAME
      
      # Add entrypoint script.
      COPY ./entrypoint.sh /bin/entrypoint.sh
      RUN chmod +x /bin/entrypoint.sh
      # Use ENTRYPOINT instead of CMD to ensure that entryscript is always executed.
      ENTRYPOINT [ "/bin/entrypoint.sh" ]
      
      # Switch user to given USERNAME otherwise Ansible will be installed as root.
      USER ${USERNAME}
      ENV PATH=$PATH:/home/${USERNAME}/.local/bin
    • devcontainer.json

      // For format details, see https://aka.ms/devcontainer.json. For config options, see the
      // README at: https://github.com/devcontainers/templates/tree/main/src/python.
      {
          "build": {
              "dockerfile": "./Dockerfile",
              "context": ".",
              "args": {
                  "FROM_IMAGE": "ghcr.io/aristanetworks/ansible-avd/base",
                  "FROM_VARIANT": "python3.11",
                  "USERNAME": "avd"
              }
          },
          "features": {
              "ghcr.io/devcontainers/features/docker-in-docker:2": {
                  "version": "latest",
                  "dockerDashComposeVersion": "none"
              },
              // Add sshd to support gh cli codespace cp.
              "ghcr.io/devcontainers/features/sshd:1": {
                  "version": "latest"
              }
          },
          "customizations": {
              "vscode": {
                  "extensions": [
                      // Git essentials.
                      "github.vscode-pull-request-github",
                      // Python.
                      "ms-python.python",
                      "ms-python.vscode-pylance",
                      // Errors and highlighters.
                      "mechatroner.rainbow-csv",
                      "oderwat.indent-rainbow",
                      // Excalidraw.
                      "pomdtr.excalidraw-editor"
                  ]
              }
          }
      }
  • copy entrypoint.sh from this PR to the root of AVD repo or .devcontainer/ and make it executable.

Tests:

  1. Check that container can be created without github repo defined and without mounts.
  • build devcontainer. It's quite long and boring. Good chance to drink a coffee, but a small one.

  • run entrypoint.sh

  • verify that there are no errors and if following commands provide meaninful results:

    • ansible --version
    • ansible-galaxy collection list
  1. Check that collection can be installed from github branch

    • add following to devcontainer.json

      "containerEnv": {
        "AVD_GITHUB_REPO": "aristanetworks/ansible-avd",
        "AVD_BRANCH_NAME": "devel"
      },
    • build container, run entrypoint.sh, verify

  2. Check that collection can be installed from a mount

    • remove env variables from devcontainer.json

    • add following settings

      "mounts": [
          "source=${localWorkspaceFolder}/ansible_collections/arista/avd,target=/home/avd/.ansible/collections/ansible_collections/arista/avd,type=bind"
      ],
    • build container, run entrypoint.sh, verify

Copy link
Contributor

@gmuloc gmuloc left a comment

Choose a reason for hiding this comment

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

LGTM

@gmuloc gmuloc merged commit fc39ade into aristanetworks:devel Jan 16, 2024
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants