feature/podman: Updating dapr cli to allow different container runtime (#1041)

* feature/podman: Updating dapr cli to allow providing of container
runtime.

- Ability to provide docker or podman runtime for init and uninstall commands
  by passing along the --container-runtime flag with values docker or
  podman.

Signed-off-by: Martin <7595909+martin-bucinskas@users.noreply.github.com>

* feature/podman: Updating install message to use the runtime environment

Signed-off-by: Martin <7595909+martin-bucinskas@users.noreply.github.com>

* feature/podman: Fixing linting issues.

- Fixing go lint issues by running gofumpt and gofmt.

Signed-off-by: Martin <7595909+martin-bucinskas@users.noreply.github.com>

* Correcting rebase

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* use podman for macos tests

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* setting env

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* adding docker host

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* Change step title and remove docker host

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* code cleanup

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* install podman mac helper

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* fix review comments

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* Refactor use of global varibale

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* matrix added for slim and complete  mode

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* correcting worflow expression

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* refactor uninstall code

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* separate uninstall test for slim and complete mode

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

Signed-off-by: Martin <7595909+martin-bucinskas@users.noreply.github.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Co-authored-by: Martin <7595909+martin-bucinskas@users.noreply.github.com>
This commit is contained in:
Pravin Pushkar 2022-08-23 21:30:50 +05:30 committed by GitHub
parent d22950672c
commit 5a28708a12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 153 additions and 73 deletions

View File

@ -37,21 +37,21 @@ jobs:
ARCHIVE_OUTDIR: dist/archives
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-10.15]
os: [ubuntu-latest, windows-latest, macOS-latest]
target_arch: [arm, arm64, amd64]
include:
- os: ubuntu-latest
target_os: linux
- os: windows-latest
target_os: windows
- os: macOS-10.15
- os: macOS-latest
target_os: darwin
exclude:
- os: windows-latest
target_arch: arm
- os: windows-latest
target_arch: arm64
- os: macOS-10.15
- os: macOS-latest
target_arch: arm
steps:
- name: Set up Go ${{ env.GOVER }}

View File

@ -32,7 +32,7 @@ on:
jobs:
self-hosted-e2e:
name: Run Self-Hosted E2E tests in ${{ matrix.target_os }}_${{ matrix.target_arch }}
name: Run Self-Hosted E2E tests in ${{ matrix.target_os }}_${{ matrix.target_arch }}_${{ matrix.dapr_install_mode }}
runs-on: ${{ matrix.os }}
env:
GOVER: 1.18
@ -45,15 +45,19 @@ jobs:
DAPR_TGZ: dapr-1.7.0.tgz
strategy:
matrix:
os: [macos-10.15, ubuntu-latest, windows-latest]
os: [macos-latest, ubuntu-latest, windows-latest]
target_arch: [amd64]
dapr_install_mode: [slim, complete]
include:
- os: ubuntu-latest
target_os: linux
- os: macOS-10.15
- os: macOS-latest
target_os: darwin
- os: windows-latest
target_os: windows
exclude:
- os: windows-latest
dapr_install_mode: complete
steps:
- name: Set up Go ${{ env.GOVER }}
uses: actions/setup-go@v2
@ -61,14 +65,18 @@ jobs:
go-version: ${{ env.GOVER }}
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Install docker - MacOS
if: matrix.os == 'macos-10.15'
- name: Install podman - MacOS
if: matrix.os == 'macos-latest' && matrix.dapr_install_mode == 'complete'
run: |
brew install --cask docker
sudo /Applications/Docker.app/Contents/MacOS/Docker --unattended --install-privileged-components
open -a /Applications/Docker.app --args --unattended --accept-license
while ! /Applications/Docker.app/Contents/Resources/bin/docker info &>/dev/null; do sleep 1; done
docker --version
sudo rm -rf `brew --cache`
brew upgrade
brew install podman
which podman-mac-helper
podman_helper=$(which podman-mac-helper)
sudo ${podman_helper} install
podman machine init
podman machine start
echo "CONTAINER_RUNTIME=podman" >> $GITHUB_ENV
- name: Determine latest Dapr Runtime version including Pre-releases
if: github.base_ref == 'master'
run: |
@ -88,7 +96,8 @@ jobs:
if: github.event.schedule == '0 */6 * * *'
env:
DAPR_DEFAULT_IMAGE_REGISTRY: ghcr
DAPR_E2E_INIT_SLIM: ${{ contains(matrix.os, 'windows-latest') }}
DAPR_E2E_INIT_SLIM: ${{ contains(matrix.os, 'windows-latest') || contains(matrix.dapr_install_mode, 'slim') }}
CONTAINER_RUNTIME: ${{ env.CONTAINER_RUNTIME }}
run: |
export TEST_OUTPUT_FILE=$GITHUB_WORKSPACE/test-e2e-standalone.json
echo "TEST_OUTPUT_FILE=$TEST_OUTPUT_FILE" >> $GITHUB_ENV
@ -98,7 +107,8 @@ jobs:
- name: Run E2E tests with Docker hub
if: github.event.schedule != '0 */6 * * *'
env:
DAPR_E2E_INIT_SLIM: ${{ contains(matrix.os, 'windows-latest') }}
DAPR_E2E_INIT_SLIM: ${{ contains(matrix.os, 'windows-latest') || contains(matrix.dapr_install_mode, 'slim') }}
CONTAINER_RUNTIME: ${{ env.CONTAINER_RUNTIME }}
run: |
export TEST_OUTPUT_FILE=$GITHUB_WORKSPACE/test-e2e-standalone.json
echo "TEST_OUTPUT_FILE=$TEST_OUTPUT_FILE" >> $GITHUB_ENV

View File

@ -180,6 +180,19 @@ dapr init --network dapr-network
> Note: When installed to a specific Docker network, you will need to add the `--placement-host-address` arguments to `dapr run` commands run in any containers within that network.
> The format of `--placement-host-address` argument is either `<hostname>` or `<hostname>:<port>`. If the port is omitted, the default port `6050` for Windows and `50005` for Linux/MacOS applies.
#### Install with a specific container runtime
You can install the Dapr runtime using a specific container runtime
environment such as Docker or Podman by passing along the
`--container-runtime` argument:
```bash
# Install Dapr with Podman
$ dapr init --container-runtime podman
```
> Note: The default container runtime is Docker.
### Uninstall Dapr in a standalone mode
Uninstalling will remove daprd binary and the placement container (if installed with Docker or the placement binary if not).
@ -211,6 +224,16 @@ If previously installed to a specific Docker network, Dapr can be uninstalled wi
dapr uninstall --network dapr-network
```
#### Uninstall Dapr from a specific container runtime
You can uninstall Dapr from a specific container runtime
environment by passing along the `--container-runtime` argument:
```bash
# Uninstall Dapr from Podman container runtime
$ dapr uninstall --container-runtime podman
```
### Install Dapr on Kubernetes
The init command will install Dapr to a Kubernetes cluster. For more advanced use cases, use our [Helm Chart](https://github.com/dapr/dapr/tree/master/charts/dapr).

View File

@ -40,6 +40,7 @@ var (
enableHA bool
values []string
fromDir string
containerRuntime string
)
var InitCmd = &cobra.Command{
@ -130,7 +131,7 @@ dapr init --from-dir <path-to-directory>
if len(imageRegistryURI) != 0 {
warnForPrivateRegFeat()
}
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir)
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime)
if err != nil {
print.FailureStatusEvent(os.Stderr, err.Error())
os.Exit(1)
@ -170,6 +171,7 @@ func init() {
InitCmd.Flags().StringVarP(&fromDir, "from-dir", "", "", "Use Dapr artifacts from local directory for self-hosted installation")
InitCmd.Flags().BoolP("help", "h", false, "Print this help message")
InitCmd.Flags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
InitCmd.Flags().String("image-registry", "", "Custom/Private docker image repository URL")
InitCmd.Flags().String("image-registry", "", "Custom/Private docker image repository url")
InitCmd.Flags().StringVarP(&containerRuntime, "container-runtime", "", "docker", "The container runtime to use (defaults to docker)")
RootCmd.AddCommand(InitCmd)
}

View File

@ -26,9 +26,10 @@ import (
)
var (
uninstallNamespace string
uninstallKubernetes bool
uninstallAll bool
uninstallNamespace string
uninstallKubernetes bool
uninstallAll bool
uninstallContainerRuntime string
)
// UninstallCmd is a command from removing a Dapr installation.
@ -58,7 +59,7 @@ dapr uninstall -k
} else {
print.InfoStatusEvent(os.Stdout, "Removing Dapr from your machine...")
dockerNetwork := viper.GetString("network")
err = standalone.Uninstall(uninstallAll, dockerNetwork)
err = standalone.Uninstall(uninstallAll, dockerNetwork, uninstallContainerRuntime)
}
if err != nil {
@ -76,5 +77,6 @@ func init() {
UninstallCmd.Flags().String("network", "", "The Docker network from which to remove the Dapr runtime")
UninstallCmd.Flags().StringVarP(&uninstallNamespace, "namespace", "n", "dapr-system", "The Kubernetes namespace to uninstall Dapr from")
UninstallCmd.Flags().BoolP("help", "h", false, "Print this help message")
UninstallCmd.Flags().StringVarP(&uninstallContainerRuntime, "container-runtime", "", "docker", "The container runtime to use (defaults to docker)")
RootCmd.AddCommand(UninstallCmd)
}

View File

@ -24,8 +24,9 @@ import (
"github.com/dapr/cli/utils"
)
func runDockerLoad(in io.Reader) error {
subProcess := exec.Command("docker", "load")
func loadContainerFromReader(in io.Reader, containerRuntime string) error {
runtimeCmd := utils.GetContainerRuntimeCmd(containerRuntime)
subProcess := exec.Command(runtimeCmd, "load")
stdin, err := subProcess.StdinPipe()
if err != nil {
@ -53,14 +54,14 @@ func runDockerLoad(in io.Reader) error {
return nil
}
func loadDocker(dir string, dockerImageFileName string) error {
func loadContainer(dir string, dockerImageFileName, containerRuntime string) error {
var imageFile io.Reader
var err error
imageFile, err = os.Open(path_filepath.Join(dir, dockerImageFileName))
if err != nil {
return fmt.Errorf("fail to read docker image file %s: %w", dockerImageFileName, err)
}
err = runDockerLoad(imageFile)
err = loadContainerFromReader(imageFile, containerRuntime)
if err != nil {
return fmt.Errorf("fail to load docker image from file %s: %w", dockerImageFileName, err)
}
@ -69,7 +70,7 @@ func loadDocker(dir string, dockerImageFileName string) error {
}
// check if the container either exists and stopped or is running.
func confirmContainerIsRunningOrExists(containerName string, isRunning bool) (bool, error) {
func confirmContainerIsRunningOrExists(containerName string, isRunning bool, runtimeCmd string) (bool, error) {
// e.g. docker ps --filter name=dapr_redis --filter status=running --format {{.Names}}.
args := []string{"ps", "--all", "--filter", "name=" + containerName}
@ -79,7 +80,7 @@ func confirmContainerIsRunningOrExists(containerName string, isRunning bool) (bo
}
args = append(args, "--format", "{{.Names}}")
response, err := utils.RunCmdAndWait("docker", args...)
response, err := utils.RunCmdAndWait(runtimeCmd, args...)
response = strings.TrimSuffix(response, "\n")
// If 'docker ps' failed due to some reason.
@ -107,7 +108,7 @@ func isContainerRunError(err error) bool {
return false
}
func parseDockerError(component string, err error) error {
func parseContainerRuntimeError(component string, err error) error {
//nolint
if exitError, ok := err.(*exec.ExitError); ok {
exitCode := exitError.ExitCode()
@ -121,11 +122,12 @@ func parseDockerError(component string, err error) error {
return err
}
func tryPullImage(imageName string) bool {
func tryPullImage(imageName, containerRuntime string) bool {
runtimeCmd := utils.GetContainerRuntimeCmd(containerRuntime)
args := []string{
"pull",
imageName,
}
_, err := utils.RunCmdAndWait("docker", args...)
_, err := utils.RunCmdAndWait(runtimeCmd, args...)
return err == nil
}

View File

@ -123,6 +123,7 @@ type initInfo struct {
dashboardVersion string
dockerNetwork string
imageRegistryURL string
containerRuntime string
}
type daprImageInfo struct {
@ -145,16 +146,17 @@ func isBinaryInstallationRequired(binaryFilePrefix, installDir string) (bool, er
}
// Init installs Dapr on a local machine using the supplied runtimeVersion.
func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMode bool, imageRegistryURL string, fromDir string) error {
func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMode bool, imageRegistryURL string, fromDir string, containerRuntime string) error {
var err error
var bundleDet bundleDetails
containerRuntime = strings.TrimSpace(containerRuntime)
fromDir = strings.TrimSpace(fromDir)
// AirGap init flow is true when fromDir var is set i.e. --from-dir flag has value.
setAirGapInit(fromDir)
if !slimMode {
// If --slim installation is not requested, check if docker is installed.
dockerInstalled := utils.IsDockerInstalled()
if !dockerInstalled {
conatinerRuntimeAvailable := utils.IsDockerInstalled() || utils.IsPodmanInstalled()
if !conatinerRuntimeAvailable {
return errors.New("could not connect to Docker. Docker may not be installed or running")
}
@ -255,6 +257,7 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod
dashboardVersion: dashboardVersion,
dockerNetwork: dockerNetwork,
imageRegistryURL: imageRegistryURL,
containerRuntime: containerRuntime,
}
for _, step := range initSteps {
// Run init on the configurations and containers.
@ -284,6 +287,7 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod
// Print info on placement binary only on slim install.
print.InfoStatusEvent(os.Stdout, "%s binary has been installed to %s.", placementServiceFilePrefix, daprBinDir)
} else {
runtimeCmd := utils.GetContainerRuntimeCmd(info.containerRuntime)
dockerContainerNames := []string{DaprPlacementContainerName, DaprRedisContainerName, DaprZipkinContainerName}
// Skip redis and zipkin in local installation mode.
if isAirGapInit {
@ -291,7 +295,7 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod
}
for _, container := range dockerContainerNames {
containerName := utils.CreateContainerName(container, dockerNetwork)
ok, err := confirmContainerIsRunningOrExists(containerName, true)
ok, err := confirmContainerIsRunningOrExists(containerName, true, runtimeCmd)
if err != nil {
return err
}
@ -299,7 +303,7 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod
print.InfoStatusEvent(os.Stdout, "%s container is running.", containerName)
}
}
print.InfoStatusEvent(os.Stdout, "Use `docker ps` to check running containers.")
print.InfoStatusEvent(os.Stdout, "Use `%s ps` to check running containers.", runtimeCmd)
}
return nil
}
@ -313,7 +317,8 @@ func runZipkin(wg *sync.WaitGroup, errorChan chan<- error, info initInfo) {
zipkinContainerName := utils.CreateContainerName(DaprZipkinContainerName, info.dockerNetwork)
exists, err := confirmContainerIsRunningOrExists(zipkinContainerName, false)
runtimeCmd := utils.GetContainerRuntimeCmd(info.containerRuntime)
exists, err := confirmContainerIsRunningOrExists(zipkinContainerName, false, runtimeCmd)
if err != nil {
errorChan <- err
return
@ -357,14 +362,14 @@ func runZipkin(wg *sync.WaitGroup, errorChan chan<- error, info initInfo) {
args = append(args, imageName)
}
_, err = utils.RunCmdAndWait("docker", args...)
_, err = utils.RunCmdAndWait(runtimeCmd, args...)
if err != nil {
runError := isContainerRunError(err)
if !runError {
errorChan <- parseDockerError("Zipkin tracing", err)
errorChan <- parseContainerRuntimeError("Zipkin tracing", err)
} else {
errorChan <- fmt.Errorf("docker %s failed with: %w", args, err)
errorChan <- fmt.Errorf("%s %s failed with: %w", runtimeCmd, args, err)
}
return
}
@ -380,7 +385,8 @@ func runRedis(wg *sync.WaitGroup, errorChan chan<- error, info initInfo) {
redisContainerName := utils.CreateContainerName(DaprRedisContainerName, info.dockerNetwork)
exists, err := confirmContainerIsRunningOrExists(redisContainerName, false)
runtimeCmd := utils.GetContainerRuntimeCmd(info.containerRuntime)
exists, err := confirmContainerIsRunningOrExists(redisContainerName, false, runtimeCmd)
if err != nil {
errorChan <- err
return
@ -422,14 +428,14 @@ func runRedis(wg *sync.WaitGroup, errorChan chan<- error, info initInfo) {
}
args = append(args, imageName)
}
_, err = utils.RunCmdAndWait("docker", args...)
_, err = utils.RunCmdAndWait(runtimeCmd, args...)
if err != nil {
runError := isContainerRunError(err)
if !runError {
errorChan <- parseDockerError("Redis state store", err)
errorChan <- parseContainerRuntimeError("Redis state store", err)
} else {
errorChan <- fmt.Errorf("docker %s failed with: %w", args, err)
errorChan <- fmt.Errorf("%s %s failed with: %w", runtimeCmd, args, err)
}
return
}
@ -443,9 +449,10 @@ func runPlacementService(wg *sync.WaitGroup, errorChan chan<- error, info initIn
return
}
runtimeCmd := utils.GetContainerRuntimeCmd(info.containerRuntime)
placementContainerName := utils.CreateContainerName(DaprPlacementContainerName, info.dockerNetwork)
exists, err := confirmContainerIsRunningOrExists(placementContainerName, false)
exists, err := confirmContainerIsRunningOrExists(placementContainerName, false, runtimeCmd)
if err != nil {
errorChan <- err
@ -467,7 +474,7 @@ func runPlacementService(wg *sync.WaitGroup, errorChan chan<- error, info initIn
// if --from-dir flag is given load the image details from the installer-bundle.
dir := path_filepath.Join(info.fromDir, *info.bundleDet.ImageSubDir)
image = info.bundleDet.getPlacementImageName()
err = loadDocker(dir, info.bundleDet.getPlacementImageFileName())
err = loadContainer(dir, info.bundleDet.getPlacementImageFileName(), info.containerRuntime)
if err != nil {
errorChan <- err
return
@ -505,14 +512,14 @@ func runPlacementService(wg *sync.WaitGroup, errorChan chan<- error, info initIn
args = append(args, image)
_, err = utils.RunCmdAndWait("docker", args...)
_, err = utils.RunCmdAndWait(runtimeCmd, args...)
if err != nil {
runError := isContainerRunError(err)
if !runError {
errorChan <- parseDockerError("placement service", err)
errorChan <- parseContainerRuntimeError("placement service", err)
} else {
errorChan <- fmt.Errorf("docker %s failed with: %w", args, err)
errorChan <- fmt.Errorf("%s %s failed with: %w", runtimeCmd, args, err)
}
return
}
@ -1172,7 +1179,7 @@ func getPlacementImageName(imageInfo daprImageInfo, info initInfo) (string, erro
// if default registry is GHCR and the image is not available in or cannot be pulled from GHCR
// fallback to using dockerhub.
if useGHCR(imageInfo, info.fromDir) && !tryPullImage(image) {
if useGHCR(imageInfo, info.fromDir) && !tryPullImage(image, info.containerRuntime) {
print.InfoStatusEvent(os.Stdout, "Placement image not found in Github container registry, pulling it from Docker Hub")
image = getPlacementImageWithTag(daprDockerImageName, info.runtimeVersion)
}

View File

@ -16,21 +16,22 @@ package standalone
import (
"errors"
"fmt"
"io/fs"
"os"
"strings"
"github.com/dapr/cli/pkg/print"
"github.com/dapr/cli/utils"
)
func removeContainers(uninstallPlacementContainer, uninstallAll bool, dockerNetwork string) []error {
func removeContainers(uninstallPlacementContainer, uninstallAll bool, dockerNetwork, runtimeCmd string) []error {
var containerErrs []error
var err error
if uninstallPlacementContainer {
containerErrs = removeDockerContainer(containerErrs, DaprPlacementContainerName, dockerNetwork)
containerErrs = removeDockerContainer(containerErrs, DaprPlacementContainerName, dockerNetwork, runtimeCmd)
_, err = utils.RunCmdAndWait(
"docker", "rmi",
runtimeCmd, "rmi",
"--force",
daprDockerImageName)
@ -42,23 +43,23 @@ func removeContainers(uninstallPlacementContainer, uninstallAll bool, dockerNetw
}
if uninstallAll {
containerErrs = removeDockerContainer(containerErrs, DaprRedisContainerName, dockerNetwork)
containerErrs = removeDockerContainer(containerErrs, DaprZipkinContainerName, dockerNetwork)
containerErrs = removeDockerContainer(containerErrs, DaprRedisContainerName, dockerNetwork, runtimeCmd)
containerErrs = removeDockerContainer(containerErrs, DaprZipkinContainerName, dockerNetwork, runtimeCmd)
}
return containerErrs
}
func removeDockerContainer(containerErrs []error, containerName, network string) []error {
func removeDockerContainer(containerErrs []error, containerName, network, runtimeCmd string) []error {
container := utils.CreateContainerName(containerName, network)
exists, _ := confirmContainerIsRunningOrExists(container, false)
exists, _ := confirmContainerIsRunningOrExists(container, false, runtimeCmd)
if !exists {
print.WarningStatusEvent(os.Stdout, "WARNING: %s container does not exist", container)
return containerErrs
}
print.InfoStatusEvent(os.Stdout, "Removing container: %s", container)
_, err := utils.RunCmdAndWait(
"docker", "rm",
runtimeCmd, "rm",
"--force",
container)
if err != nil {
@ -82,25 +83,26 @@ func removeDir(dirPath string) error {
// Uninstall reverts all changes made by init. Deletes all installed containers, removes default dapr folder,
// removes the installed binary and unsets env variables.
func Uninstall(uninstallAll bool, dockerNetwork string) error {
func Uninstall(uninstallAll bool, dockerNetwork string, containerRuntime string) error {
var containerErrs []error
daprDefaultDir := defaultDaprDirPath()
daprBinDir := defaultDaprBinPath()
placementFilePath := binaryFilePath(daprBinDir, placementServiceFilePrefix)
_, placementErr := os.Stat(placementFilePath) // check if the placement binary exists.
uninstallPlacementContainer := os.IsNotExist(placementErr)
uninstallPlacementContainer := errors.Is(placementErr, fs.ErrNotExist)
// Remove .dapr/bin.
err := removeDir(daprBinDir)
if err != nil {
print.WarningStatusEvent(os.Stdout, "WARNING: could not delete dapr bin dir: %s", daprBinDir)
}
dockerInstalled := false
dockerInstalled = utils.IsDockerInstalled()
if dockerInstalled {
containerErrs = removeContainers(uninstallPlacementContainer, uninstallAll, dockerNetwork)
containerRuntime = strings.TrimSpace(containerRuntime)
runtimeCmd := utils.GetContainerRuntimeCmd(containerRuntime)
conatinerRuntimeAvailable := false
conatinerRuntimeAvailable = utils.IsDockerInstalled() || utils.IsPodmanInstalled()
if conatinerRuntimeAvailable {
containerErrs = removeContainers(uninstallPlacementContainer, uninstallAll, dockerNetwork, runtimeCmd)
}
if uninstallAll {
@ -111,10 +113,6 @@ func Uninstall(uninstallAll bool, dockerNetwork string) error {
}
err = errors.New("uninstall failed")
if uninstallPlacementContainer && !dockerInstalled {
// if placement binary did not exist before trying to delete it and not able to connect to docker.
return fmt.Errorf("%w \ncould not delete placement service. Either the placement binary is not found, or Docker may not be installed or running", err)
}
if len(containerErrs) == 0 {
return nil

View File

@ -49,11 +49,13 @@ func cmdDashboard(ctx context.Context, port string) error {
// Arguments to the init command can be passed via args.
func cmdInit(runtimeVersion string, args ...string) (string, error) {
initArgs := []string{"init", "--log-as-json", "--runtime-version", runtimeVersion}
daprContainerRuntime := containerRuntime()
if isSlimMode() {
initArgs = append(initArgs, "--slim")
} else if daprContainerRuntime != "" {
initArgs = append(initArgs, "--container-runtime", daprContainerRuntime)
}
initArgs = append(initArgs, args...)
return spawn.Command(common.GetDaprPath(), initArgs...)
@ -118,6 +120,10 @@ func cmdStop(appId string, args ...string) (string, error) {
// cmdUninstall uninstalls Dapr with --all flag and returns the command output and error.
func cmdUninstall() (string, error) {
daprContainerRuntime := containerRuntime()
if !isSlimMode() && daprContainerRuntime != "" {
return spawn.Command(common.GetDaprPath(), "uninstall", "--container-runtime", daprContainerRuntime, "--all")
}
return spawn.Command(common.GetDaprPath(), "uninstall", "--all")
}

View File

@ -61,9 +61,11 @@ func TestStandaloneInitNegatives(t *testing.T) {
require.Contains(t, output, "Removing Dapr from your machine...", "expected output to contain message")
path := filepath.Join(homeDir, ".dapr", "bin")
require.Contains(t, output, "WARNING: "+path+" does not exist", "expected output to contain message")
require.Contains(t, output, "WARNING: dapr_placement container does not exist", "expected output to contain message")
require.Contains(t, output, "WARNING: dapr_redis container does not exist", "expected output to contain message")
require.Contains(t, output, "WARNING: dapr_zipkin container does not exist", "expected output to contain message")
if !isSlimMode() {
require.Contains(t, output, "WARNING: dapr_placement container does not exist", "expected output to contain message")
require.Contains(t, output, "WARNING: dapr_redis container does not exist", "expected output to contain message")
require.Contains(t, output, "WARNING: dapr_zipkin container does not exist", "expected output to contain message")
}
path = filepath.Join(homeDir, ".dapr")
require.Contains(t, output, "WARNING: "+path+" does not exist", "expected output to contain message")
require.Contains(t, output, "Dapr has been removed successfully")

View File

@ -146,3 +146,10 @@ func ensureDaprInstallation(t *testing.T) {
require.NoError(t, err, "failed to create components")
}
}
func containerRuntime() string {
if daprContainerRuntime, ok := os.LookupEnv("CONTAINER_RUNTIME"); ok {
return daprContainerRuntime
}
return ""
}

View File

@ -35,10 +35,23 @@ import (
"gopkg.in/yaml.v2"
)
type ContainerRuntime string
const (
DOCKER ContainerRuntime = "docker"
socketFormat = "%s/dapr-%s-%s.socket"
)
func GetContainerRuntimeCmd(containerRuntime string) string {
switch len(containerRuntime) {
case 0:
return string(DOCKER)
default:
return containerRuntime
}
}
// PrintTable to print in the table format.
func PrintTable(csvContent string) {
WriteTable(os.Stdout, csvContent)
@ -145,6 +158,14 @@ func IsDockerInstalled() bool {
return err == nil
}
func IsPodmanInstalled() bool {
cmd := exec.Command("podman", "version")
if err := cmd.Run(); err != nil {
return false
}
return true
}
// IsDaprListeningOnPort checks if Dapr is litening to a given port.
func IsDaprListeningOnPort(port int, timeout time.Duration) error {
start := time.Now()