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 caddy server as system install #1070

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nitishkumar71
Copy link
Contributor

Description

Motivation and Context

How Has This Been Tested?

Executed the command arkade system install caddy produced below output

Installing Caddy Server to /usr/local/bin
Installing version: v2.7.6 for: amd64
Downloading from: https://github.com/caddyserver/caddy/releases/download/v2.7.6/caddy_2.7.6_linux_amd64.tar.gz
13.98 MiB / 13.98 MiB [--------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00%
Downloaded to: /tmp/arkade-345065249/caddy_2.7.6_linux_amd64.tar.gz
Unpacking Caddy to: /usr/local/bin/caddy

If updating or adding a new CLI to arkade get, run:

go build && ./hack/test-tool.sh TOOL_NAME

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Documentation

  • I have updated the list of tools in README.md if (required) with ./arkade get --format markdown
  • I have updated the list of apps in README.md if (required) with ./arkade install --help

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have tested this on arm, or have added code to prevent deployment

}

command.Flags().StringP("version", "v", "", "The version or leave blank to determine the latest available version")
command.Flags().String("path", "/usr/local/bin", "Installation path, where a caddy subfolder will be created")
Copy link
Owner

Choose a reason for hiding this comment

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

It's not the usual pattern, but Caddy installs to /usr/bin/

Have a look at the faasd script to see what else may be missing, including adding users etc.

For adding users, we will need to detect the OS from /etc/os-release and reject the command if it's not debian or ubuntu.

In the future, if someone needs this for Alpine or Fedora, they can add a patch to run useradd with the correct syntax for their distro.

There are also some directories created and chmod is run.

Copy link
Owner

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

Good start, but there's more needed for a system install to match how Caddy is installed with faasd: https://github.com/openfaas/faasd/blob/master/hack/install.sh

@nitishkumar71 nitishkumar71 marked this pull request as draft May 29, 2024 13:23
@alexellis
Copy link
Owner

alexellis commented May 29, 2024

The new changes look like what I was expecting.

Could you test this and see if Caddy starts up correctly on a new Linux VM you create somewhere?

If you need a sample Caddyfile, you can change the domains for the below:

faasd.example.com {
    reverse_proxy 127.0.0.1:8080
}

}

commands := strings.Join(shellCmds, "; ")
if err = exec.Command(commands).Run(); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

Could you try go-execute which is used elsewhere? It has a shell option if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// TODO: Add empty CaddyFile and if required FAAS_DOMAIN setup too

shellCmds := []string{
"$SUDO chown --recursive caddy:caddy /var/lib/caddy",
Copy link
Owner

Choose a reason for hiding this comment

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

I think $SUDO could be removed, and arkade could be run as sudo arkade if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


caddyUser := "caddy"
if _, err = user.Lookup(caddyUser); errors.Is(err, user.UnknownUserError(caddyUser)) {
addUserCmd := fmt.Sprintf("$SUDO useradd --system --home %s --shell /bin/false %s", caddyHomeDir, caddyUser)
Copy link
Owner

Choose a reason for hiding this comment

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

Try go-execute again which splits out cmd vs args

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@alexellis
Copy link
Owner

@nitishkumar71 suggested using the "get" method from the tools code. I think it would be worth trying out as an experiment.

@nitishkumar71
Copy link
Contributor Author

Re-executing system install produced below output

Installing Caddy Server to /usr/bin
Downloading: https://github.com/caddyserver/caddy/releases/download/v2.8.1/caddy_2.8.1_linux_amd64.tar.gz
13.92 MiB / 13.92 MiB [-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00%
/tmp/arkade-2170843838/caddy_2.8.1_linux_amd64.tar.gz written.
2024/06/02 01:51:25 Extracted: /tmp/arkade-2170843838/caddy
2024/06/02 01:51:25 Copying /tmp/arkade-2170843838/caddy to /usr/bin/caddy
Downloaded caddy.service file to /tmp/arkade-2005628698/caddy.service
Copied caddy.service file to /etc/systemd/system/caddy.service
Created caddy home /var/lib/caddy and Conf /etc/caddy directory
User created for caddy server.
Created symlink /etc/systemd/system/multi-user.target.wants/caddy.service → /etc/systemd/system/caddy.service.

@nitishkumar71 nitishkumar71 marked this pull request as ready for review June 1, 2024 20:24
return err
}

if _, err = executeShellCmd(context.Background(), "systemctl", "start", "caddy"); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

Skip the start, and then you can also omit createCaddyConf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return fmt.Errorf("this app only supports Linux")
}

tools := get.MakeTools()
Copy link
Owner

@alexellis alexellis Jun 5, 2024

Choose a reason for hiding this comment

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

Does this change mean that "caddy" also appears via arkade get caddy?

In the case of things like Go or Node, we won't that because it won't do the right thing. We could have an additional flag or bool etc on each Tool to hide them from the arkade get command

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. will start working toward migrating system apps to use this new approach and enable apps which we want as system install only


tools := get.MakeTools()
var tool *get.Tool
for _, t := range tools {
Copy link
Owner

Choose a reason for hiding this comment

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

I like this approach. Could you create an issue to retrofit this into the existing system install apps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I would try to progressively apply this approach in system install apps.

Copy link
Owner

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

Could you see the suggestions please?

Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com>
Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Caddy Server as System install
2 participants