How to use getArchType method of main Package

Best Rod code snippet using main.getArchType

ducker.go

Source:ducker.go Github

copy

Full Screen

...24 err := cmdRun.Run()25 checkError(err)26 return strings.TrimSpace(cmdOut.String())27}28func getArchType() string {29 return runTerminalCmd("uname", "-m")30}31func writeFile(contents string, path string, overwrite bool) bool {32 _, err := os.Stat(path)33 if !overwrite && err == nil {34 fmt.Printf("%s already exist!\n", path)35 return false36 }37 fp, err := os.Create(path)38 checkError(err)39 write_buf := bufio.NewWriter(fp)40 _, err = write_buf.WriteString(contents)41 write_buf.Flush()42 checkError(err)43 return true44}45func dockerBuild(ctx *cli.Context, dockerTag string) {46 dockerFilePath := "docker/Dockerfile"47 if !strings.HasSuffix(dockerTag, "x86_64") {48 dockerFilePath += "." + getArchType()49 }50 buildArgs := ctx.String("args")51 buildCmd := "docker build . -t " + dockerTag52 buildCmd += " -f " + dockerFilePath53 buildCmd += " --build-arg UID=" + runTerminalCmd("id", "-u")54 buildCmd += " --build-arg GID=" + runTerminalCmd("id", "-g")55 if buildArgs != "" {56 buildCmd += " " + buildArgs57 }58 cmdRun := exec.Command("/bin/sh", "-c", buildCmd)59 cmdRun.Stdout = os.Stdout60 if err := cmdRun.Run(); err != nil {61 fmt.Println(err)62 }63}64func dockerRun(ctx *cli.Context, dockerTag string) {65 dockerArgs := ctx.String("docker-args")66 shellType := ctx.String("shell")67 mountPWD := ctx.Bool("mount-pwd")68 shellCmd := "/bin/bash"69 dockerOpt := "-tid"70 if shellType == "zsh" {71 shellCmd = "/usr/bin/zsh"72 } else if shellType == "nosh" {73 shellCmd = ctx.String("run-cmd")74 dockerOpt = "-ti"75 }76 runCmd := "docker run --privileged " + dockerOpt77 runCmd += " -e DISPLAY=" + os.Getenv("DISPLAY")78 runCmd += " -e TERM=xterm-256color"79 runCmd += " -v /tmp/.X11-unix:/tmp/.X11-unix:ro"80 runCmd += " -v /dev:/dev"81 if mountPWD {82 mydir, err := os.Getwd()83 if err != nil {84 fmt.Println(err)85 } else {86 baseDir := filepath.Base(mydir)87 projectName := strings.ToLower(baseDir)88 runCmd += " -v " + mydir + ":/home/user/" + projectName89 }90 }91 // Add GPU option if NVIDIA driver exist92 if _, err := os.Stat("/proc/driver/nvidia/version"); err == nil {93 runCmd += " --gpus all"94 }95 // Mount if .gitconfig exists96 gitConfigPath := filepath.Join(os.Getenv("HOME"), ".gitconfig")97 if _, err := os.Stat(gitConfigPath); err == nil {98 runCmd += " -v " + gitConfigPath + ":/home/user/.gitconfig"99 }100 runCmd += " --network host"101 runCmd += " " + dockerArgs102 runCmd += " " + dockerTag103 runCmd += " " + shellCmd104 fmt.Println(runCmd)105 cmdRun := exec.Command("/bin/sh", "-c", runCmd)106 cmdRun.Stdout = os.Stdout107 cmdRun.Stderr = os.Stderr108 cmdRun.Stdin = os.Stdin109 if err := cmdRun.Run(); err != nil {110 fmt.Println(err)111 }112 lastContainerID := runTerminalCmd("docker", "ps -qn 1")113 writeFile(lastContainerID, ".last_exec_cont_id.txt", true)114 if shellType != "nosh" {115 dockerExec(ctx)116 }117}118func dockerExec(ctx *cli.Context) {119 shellType := ctx.String("shell")120 shellCmd := "/bin/bash"121 if shellType == "zsh" {122 shellCmd = "/usr/bin/zsh"123 }124 lastContainerID := runTerminalCmd("tail", "-1 .last_exec_cont_id.txt")125 execCmd := "docker exec -ti " + lastContainerID126 execCmd += " " + shellCmd127 cmdExec := exec.Command("/bin/sh", "-c", execCmd)128 cmdExec.Stdout = os.Stdout129 cmdExec.Stderr = os.Stderr130 cmdExec.Stdin = os.Stdin131 if err := cmdExec.Run(); err != nil {132 fmt.Println(err)133 }134}135func initDockerfile(ctx *cli.Context) {136 name := ctx.String("name")137 contact := ctx.String("contact")138 template := ctx.String("template")139 forceOverwrite := ctx.Bool("force")140 fmt.Println(template)141 templateContent := checkTemplates(template)142 if !ctx.Bool("quite") {143 reader := bufio.NewReader(os.Stdin)144 fmt.Printf("Enter your name(Default: %s): ", name)145 keyIn, err := reader.ReadString('\n')146 checkError(err)147 if strings.TrimSpace(keyIn) != "" {148 name = keyIn149 }150 name = strings.TrimSpace(name)151 fmt.Printf("Enter contact address (Default: %s): ", contact)152 keyIn, err = reader.ReadString('\n')153 checkError(err)154 if strings.TrimSpace(keyIn) != "" {155 contact = keyIn156 }157 contact = strings.TrimSpace(contact)158 }159 tzname, _ := tzlocal.RuntimeTZ()160 dockerBaseImage := "ubuntu:bionic"161 dockerContents := fmt.Sprintf("FROM %s\n\n", dockerBaseImage)162 dockerContents += fmt.Sprintf("LABEL maintainer=\"%s <%s>\"\n\n", name, contact)163 dockerContents += "ENV DEBIAN_FRONTEND=noninteractive\n"164 dockerContents += fmt.Sprintf("ENV TZ=%s\n", tzname)165 dockerContents += "ENV TERM xterm-256color\n\n"166 dockerContents += "ARG UID=1000\n"167 dockerContents += "ARG GID=1000\n"168 dockerContents += "RUN groupadd -g $GID -o user && useradd -m -u $UID -g $GID -o -s /bin/bash user\n\n"169 dockerContents += "RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone\n"170 dockerContents += "RUN apt-get update && apt-get install -y sudo dialog apt-utils tzdata\n"171 dockerContents += "RUN echo \"%sudo ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers && echo \"user:user\" | chpasswd && adduser user sudo\n\n"172 dockerContents += "WORKDIR /home/user\n"173 dockerContents += "USER user\n\n"174 dockerContents += "RUN sudo apt-get update && sudo apt-get install -y libgl1-mesa-dev && sudo apt-get -y install jq\n\n"175 dockerContents += "ENV NVIDIA_VISIBLE_DEVICES ${NVIDIA_VISIBLE_DEVICES:-all}\n"176 dockerContents += "ENV NVIDIA_DRIVER_CAPABILITIES ${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics\n\n"177 dockerContents += "RUN sudo apt-get update && sudo apt-get -y install wget curl git\n"178 dockerContents += "RUN curl -s https://raw.githubusercontent.com/JeiKeiLim/my_term/main/run.sh | /bin/bash\n\n"179 dockerContents += "RUN sudo apt-get update && sudo apt-get install -y zsh && \\\n"180 dockerContents += " sh -c \"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\" \"\" --unattended && \\\n"181 dockerContents += " git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k\n"182 dockerContents += "RUN echo \"\\n# Custom settings\" >> /home/user/.zshrc && \\\n"183 dockerContents += " echo \"export PATH=/home/user/.local/bin:$PATH\" >> /home/user/.zshrc && \\\n"184 dockerContents += " echo \"export LC_ALL=C.UTF-8 && export LANG=C.UTF-8\" >> /home/user/.zshrc && \\\n"185 dockerContents += " sed '11 c\\ZSH_THEME=powerlevel10k/powerlevel10k' ~/.zshrc > tmp.txt && mv tmp.txt ~/.zshrc && \\\n"186 dockerContents += " echo 'POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true' >> ~/.zshrc\n"187 if templateContent != "" {188 dockerContents += "\n"189 dockerContents += templateContent190 }191 dockerContents += "\n# Place your environment here\n\n"192 err := os.Mkdir("docker", os.ModePerm)193 if !forceOverwrite {194 checkError(err)195 }196 isSuccess1 := writeFile(dockerContents, "docker/Dockerfile", forceOverwrite)197 isSuccess2 := writeFile(dockerContents, "docker/Dockerfile.aarch64", forceOverwrite)198 if isSuccess1 && isSuccess2 {199 fmt.Println("Success!")200 fmt.Println("Dockerfile has been created in docker directory")201 } else {202 fmt.Println("Failed")203 fmt.Println("Dockerfile already exist in docker directory")204 }205}206func main() {207 mydir, err := os.Getwd()208 if err != nil {209 fmt.Println(err)210 }211 organizationName := "jeikeilim"212 baseDir := filepath.Base(mydir)213 projectName := strings.ToLower(baseDir)214 osArchType := getArchType()215 dockerTag := fmt.Sprintf("%s/%s:%s", organizationName, projectName, osArchType)216 app := &cli.App{217 Name: "ducker",218 Version: "0.1.1",219 Compiled: time.Now(),220 Authors: []*cli.Author{221 &cli.Author{222 Name: "Jongkuk Lim",223 Email: "lim.jeikei@gmail.com",224 },225 },226 EnableBashCompletion: true,227 Usage: "Ducker the docker helper",228 Commands: []*cli.Command{...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...19 ver := ""20 if len(m) > 1 {21 ver = m[1]22 }23 at := getArchType()24 if master {25 releaseLatest(at)26 } else if ver != "" {27 releaseWithVer(ver, at)28 } else {29 test(at)30 }31}32func releaseLatest(at archType) {33 login()34 test(at)35 utils.Exec("docker push", at.tagDev())36 utils.Exec("docker push", at.tag())37}38func releaseWithVer(ver string, at archType) {39 login()40 verImageDev := registry + ":" + ver + "-dev"41 utils.Exec("docker manifest create", verImageDev, archAmd.tagDev(), archArm.tagDev())42 utils.Exec("docker manifest push", verImageDev)43 verImage := registry + ":" + ver44 utils.Exec("docker manifest create", verImage, archAmd.tag(), archArm.tag())45 utils.Exec("docker manifest push", verImage)46 registryDev := registry + ":dev"47 utils.Exec("docker manifest create", registryDev, archAmd.tagDev(), archArm.tagDev())48 utils.Exec("docker manifest push", registryDev)49 utils.Exec("docker manifest create", registry, archAmd.tag(), archArm.tag())50 utils.Exec("docker manifest push", registry)51}52func test(at archType) {53 utils.Exec("docker build -f=lib/docker/Dockerfile", "--platform", at.platform(), "-t", at.tag(), description(false), ".")54 utils.Exec("docker build -f=lib/docker/dev.Dockerfile",55 "--platform", at.platform(),56 "--build-arg", "golang="+at.golang(),57 "--build-arg", "nodejs="+at.nodejs(),58 "-t", at.tagDev(),59 description(true), ".",60 )61 utils.Exec("docker run", at.tag(), "rod-manager", "-h")62 // TODO: arm cross execution for chromium doesn't work well on github actions.63 if at != archArm {64 wd, err := os.Getwd()65 utils.E(err)66 utils.Exec("docker run -w=/t -v", fmt.Sprintf("%s:/t", wd), at.tagDev(), "go", "test")67 }68}69func login() {70 cmd := exec.Command("docker", "login", "-u=rod-robot", "-p", os.Getenv("DOCKER_TOKEN"), registry)71 out, err := cmd.CombinedOutput()72 utils.E(err)73 utils.E(os.Stdout.Write(out))74}75var headSha = strings.TrimSpace(utils.ExecLine(false, "git", "rev-parse", "HEAD"))76func description(dev bool) string {77 f := "Dockerfile"78 if dev {79 f = "dev." + f80 }81 return `--label=org.opencontainers.image.description=https://github.com/go-rod/rod/blob/` + headSha + "/lib/docker/" + f82}83const registry = "ghcr.io/go-rod/rod"84type archType int85const (86 archAmd archType = iota87 archArm88)89func getArchType() archType {90 arch := os.Getenv("ARCH")91 switch arch {92 case "arm":93 return archArm94 default:95 return archAmd96 }97}98func (at archType) platform() string {99 switch at {100 case archArm:101 return "linux/arm64"102 default:103 return "linux/amd64"...

Full Screen

Full Screen

download.go

Source:download.go Github

copy

Full Screen

1package download2import (3 "flag"4 "fmt"5 "runtime"6 "strings"7 "autopard.com/desa/base"8 "autopard.com/desa/common"9)10var Cmd = &base.Command{11 UsageLine: "download",12 Long: `download software.`,13 // Commands initialized in package main14 Run: Run,15}16func Run(cmd *base.Command, args []string) {17 cmdSet := flag.NewFlagSet("setup", flag.ContinueOnError)18 //var g = setupSet.Bool("g", false, "generate sample config")19 //var l = setupSet.Bool("l", false, "list targets")20 //var m = setupSet.String("m", "", "mac address of target to wake")21 //var n = setupSet.String("n", "", "name of target to wake")22 // setupSet.Parse(args)23 if len(args) < 1 {24 fmt.Printf("miss target")25 return26 }27 cmdSet.Parse(args[1:])28 target := args[0]29 fmt.Println("download", target)30 build := BUILD_STABLE31 os := common.GetOsType()32 //os := common.OS_WINDOWS33 //os := common.OS_LINUX34 //os := common.OS_DARWIN35 arch := common.GetArchType()36 //arch := common.ARCH_X8637 //arch := common.ARCH_AMD6438 //arch := common.ARCH_ARM39 //arch := common.ARCH_ARM6440 //arch := common.ARCH_UNIVERSAL41 pkg := common.PACKAGE_UNKNOWN42 switch target {43 case "vscode":44 if os == common.OS_LINUX && pkg == common.PACKAGE_UNKNOWN {45 osInfo := common.GetOsVersionInfo()46 //fmt.Println(osInfo)47 switch strings.ToLower(osInfo.Name) {48 case "ubuntu", "debian":49 pkg = common.PACKAGE_DEB50 case "centos", "fordera":51 pkg = common.PACKAGE_RPM52 default:53 pkg = common.PACKAGE_ARCHIVE54 }55 }56 err := DownloadVscode(build, os, arch, pkg)57 if err != nil {58 fmt.Println(err)59 }60 case "nomachine":61 switch runtime.GOOS {62 case "linux":63 if pkg == common.PACKAGE_UNKNOWN {64 osInfo := common.GetOsVersionInfo()65 //fmt.Println(osInfo)66 switch strings.ToLower(osInfo.Name) {67 case "ubuntu", "debian":68 pkg = common.PACKAGE_DEB69 case "centos", "fordera":70 pkg = common.PACKAGE_RPM71 default:72 pkg = common.PACKAGE_ARCHIVE73 }74 }75 case "windows":76 if pkg == common.PACKAGE_UNKNOWN {77 pkg = common.PACKAGE_EXE78 }79 }80 err := DownloadNomachine(build, os, arch, pkg)81 if err != nil {82 fmt.Println(err)83 }84 case "vmware":85 err := DownloadVmware(build, os, arch, pkg)86 if err != nil {87 fmt.Println(err)88 }89 }90}...

Full Screen

Full Screen

getArchType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(runtime.GOARCH)4}5import (6func main() {7 fmt.Println(runtime.GOOS)8}9import (10func main() {11 fmt.Println(runtime.GOOS)12 fmt.Println(runtime.GOARCH)13}14import (15func main() {16 fmt.Println(runtime.GOOS)17 fmt.Println(runtime.GOARCH)18 fmt.Println(runtime.GOEXE)19}20import (21func main() {22 fmt.Println(runtime.GOOS)23 fmt.Println(runtime.GOARCH)24 fmt.Println(runtime.GOEXE)25 fmt.Println(runtime.GOROOT())26}27import (28func main() {29 fmt.Println(runtime.GOOS)30 fmt.Println(runtime.GOARCH)31 fmt.Println(runtime.GOEXE)32 fmt.Println(runtime.GOROOT())33 fmt.Println(runtime.NumCPU())34}35import (36func main() {37 fmt.Println(runtime.GOOS)38 fmt.Println(runtime.GOARCH)39 fmt.Println(runtime.GOEXE)40 fmt.Println(runtime.GOROOT())41 fmt.Println(runtime.NumCPU())42 fmt.Println(runtime.NumGoroutine())43}44import (45func main() {46 fmt.Println(runtime.GOOS)47 fmt.Println(runtime.GOARCH)48 fmt.Println(runtime.GOEXE)49 fmt.Println(runtime.GOROOT())50 fmt.Println(runtime.NumCPU())51 fmt.Println(runtime.NumGoroutine())52 wg.Add(1)53 go func() {54 fmt.Println("Hello from inside a go routine")55 wg.Done()56 }()57 fmt.Println(runtime.NumGor

Full Screen

Full Screen

getArchType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(stringutil.Reverse("!oG ,olleH"))4 fmt.Println(stringutil.MyName)5 fmt.Println(stringutil.getArchType())6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful