I'm trying to make a Go app using the (unoffical) Standard Go Project Layout. What I don't understand is how I should import the packages in the internal directory.
This is my project
Using the Dockerfile, which copies the internal directory to the $GOPATH, it works:
~/go/src/project-layout$ docker build --no-cache .
(...)
Step 5/7 : RUN ls -la /go/src
---> Running in a27235b0bbef
total 24
drwxrwxrwx 1 root root 4096 Apr 29 07:05 .
drwxrwxrwx 1 root root 4096 Apr 12 22:23 ..
-rw-rw-r-- 1 root root 556 Apr 29 06:06 README.md
drwxrwxr-x 3 root root 4096 Apr 29 06:08 app
drwxr-xr-x 1 root root 4096 Apr 29 07:05 myproject
drwxrwxr-x 3 root root 4096 Apr 29 06:11 pkg
Removing intermediate container a27235b0bbef
---> bb924f8f88f0
Step 6/7 : RUN go build -o myapp ./cmd/myapp/main.go
---> Running in 06bd6cd778d2
Removing intermediate container 06bd6cd778d2
---> 31184f9224c8
Step 7/7 : RUN ./myapp
---> Running in baf75d4dd503
Hello World, from myapp main
Hello world, from myapp internals
Hello world, from myprivatelib: 'myapp internal'
Hello world, from myprivatelib: 'myapp main'
Removing intermediate container baf75d4dd503
---> 5747b6b4686f
Successfully built 5747b6b4686f
However, when I try to build locally, I get:
~/go/src/project-layout$ go build -o myapp ./cmd/myapp/main.go
cmd/myapp/main.go:6:2: cannot find package "app/myapp" in any of:
/home/comavn/go/src/project-layout/vendor/app/myapp (vendor tree)
/usr/lib/go-1.10/src/app/myapp (from $GOROOT)
/home/comavn/go/src/app/myapp (from $GOPATH)
cmd/myapp/main.go:7:2: cannot find package "pkg/myprivatelib" in any of:
/home/comavn/go/src/project-layout/vendor/pkg/myprivatelib (vendor tree)
/usr/lib/go-1.10/src/pkg/myprivatelib (from $GOROOT)
/home/comavn/go/src/pkg/myprivatelib (from $GOPATH)
I can get it to work by symlinking internal/app and internal/pkg in the vendor directory, but that seems wrong...
So, what am I doing wrong here? How should I import these internal packages?
I think I found the proper solution: https://github.com/ComaVN/project-layout/commit/6415a8f06dd7fbdcf1c7282bc3ec172c3e145611
You have to import using the project name as well:
import (
"project-layout/internal/app/myapp"
"project-layout/internal/pkg/myprivatelib"
)
Unfortunatly, this does mean that the build depends on the exact directory name used for the project.
Related
I keep running into that error on the last line and have tried putting the dockerfile in the tmp folder but still get the same error; I even tried upper casing and lowercasing the docker file name, it didn't resolve the issue.
my file path is Users/maheenk/Desktop/infra
my docker file :
#syntax=docker/dockerfile:1
#using latest version
FROM golang:latest
WORKDIR /app
#Download necessary Go modules
COPY go.mod ./
COPY go.sum ./
RUN go mod download
#copies source code onto image
COPY *.go ./
#static application in rootfilesystem
RUN docker build -t internhw:latest -f .Dockerfile .
EXPOSE 8080
#command to execute when image is used to start a container
CMD [ "internhw"]
the command I run in terminal:
docker build -t internhw:latest -f .Dockerfile .
what the output is in terminal:
[+] Building 0.1s (2/2) FINISHED
=> [internal] load build definition from .Dockerfile 0.1s
=> => transferring dockerfile: 2B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount200403056/.Dockerfile: no such file or directory
Output of command in terminal: ls -al
total 160
drwxrwxr-x# 9 maheenk staff 288 Apr 24 11:42 .
drwxrwxrwx# 110 maheenk staff 3520 Apr 23 17:24 ..
-rw-r--r--# 1 maheenk staff 6148 Apr 24 11:42 .DS_Store
drwxr-xr-x 14 maheenk staff 448 Apr 24 11:00 .git
-rw-r--r--# 1 maheenk staff 523 Apr 24 10:54 Dockerfile
-rw-r--r-- 1 maheenk staff 669 Apr 23 16:26 go.mod
-rw-r--r-- 1 maheenk staff 56262 Apr 23 16:26 go.sum
-rw-r--r-- 1 maheenk staff 2126 Apr 23 16:09 main.go
I added a .Dockerfile to the folder(basically a copy of the dockerfile that i renamed by putting a period in front of)
drwxrwxr-x# 9 maheenk staff 288 Apr 24 13:03 .
drwxrwxrwx# 111 maheenk staff 3552 Apr 24 12:43 ..
-rw-r--r--# 1 maheenk staff 6148 Apr 24 13:03 .DS_Store
-rw-r--r--# 1 maheenk staff 513 Apr 24 13:06 .Dockerfile
drwxr-xr-x 14 maheenk staff 448 Apr 24 13:00 .git
-rw-r--r--# 1 maheenk staff 523 Apr 24 10:54 Dockerfile
-rw-r--r-- 1 maheenk staff 669 Apr 23 16:26 go.mod
-rw-r--r-- 1 maheenk staff 56262 Apr 23 16:26 go.sum
-rw-r--r-- 1 maheenk staff 2126 Apr 23 16:09 main.go```
UPDATED VERSION:
redid the run line in docker as suggested
#syntax=docker/dockerfile:1
FROM golang:latest
WORKDIR /app
# Download necessary Go modules
COPY go.mod ./
COPY go.sum ./
RUN go mod download
#copies source code onto image
COPY *.go ./
#static application in rootfilesystem
RUN build -t internhw:latest .Dockerfile .
EXPOSE 8080
#command to execute when image is used to start a container
CMD [ "internhw" ] ```
when i run in terminal docker build -t internhw:latest .Dockerfile .
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
It does make little sense to do a docker build inside a Dockerfile which is itself... 'docker built'.
If you need to add resources to an existing image, you can use COPY or ADD inside your Dockerfile.
If you need to compile something and put the result in an existing image, you can use a multi-stage build.
Any custom metasploit module I create isn't getting loaded.
I tried both of these demos:
https://www.offensive-security.com/metasploit-unleashed/building-module/ https://github.com/rapid7/metasploit-framework/wiki/Loading-External-Modules
and got the same result that the modules were NOT found.
Before posting here, I checked these out:
https://forums.kali.org/showthread.php?28940-Metasploit-modules-not-loading!
https://www.offensive-security.com/metasploit-unleashed/modules-and-locations
and from SO:
I can't get new modules to load in metasploit
How to add module in Metasploit?
no help
Just working with the github example, on the Kali host, I do indeed have the file in the right location (according to the demo):
root#kali:~/.msf4/modules/exploits/test# ls -al
total 12
drwxr-xr-x 2 root root 4096 Mar 19 13:59 .
drwxr-xr-x 3 root root 4096 Mar 19 13:58 ..
-rw-r--r-- 1 root root 9 Mar 19 13:59 test_module.rb
I then ran reload_all and when using this command:
use exploit/test/test_module it returns with Failed to load module.
I also tried to manually load that path and it failed too:
msf > loadpath ~/.msf4/modules/
Loaded 0 modules:
Posting the answer for anyone who may come across this. I'm kinda new to this; didn't know where metasploit info gets logged.
It's in: ~/.msf4/logs/framework.log
The log told me I had a syntax error... must have happened from copying and pasting the text from the browser. Cleaned that up and everything works.
I have IntelliJ CE and I just imported a Go project that I cloned from GitHub. On my Mac, I have some folder organization where I group projects that I work on based on the technologies. For example., in my Projects folder on my Mac, I have the following sub folders:
- go-projects
- scala-projects
- rust-projects
- ruby-projects
So I obviously checked out the Go project in the go-projects folder which looks like this:
Joes-MacBook-Pro:go-projects joe$ ll
total 0
drwxr-xr-x 3 joe staff 102B Oct 28 07:51 bin/
drwxr-xr-x 19 joe staff 646B Oct 24 06:48 golang-restful-starter-kit/
drwxr-xr-x 3 joe staff 102B Oct 28 07:51 pkg/
drwxr-xr-x 3 joe staff 102B Oct 27 10:23 src/
And if I get into the src folder, it looks like this:
Joes-MacBook-Pro:go-projects joe$ cd src
total 0
drwxr-xr-x 6 joe staff 204B Nov 7 19:14 github.com/
Joes-MacBook-Pro:src joe$ cd github.com/
total 0
drwxr-xr-x 3 joe staff 102B Oct 28 08:20 btcsuite/
drwxr-xr-x 16 joe staff 544B Nov 7 19:16 eth-client/
drwxr-xr-x 3 joe staff 102B Oct 27 10:24 ethereum/
drwxr-xr-x 3 joe staff 102B Oct 28 07:51 tools/
Joes-MacBook-Pro:github.com joe$
Here is my Go related environment settings:
# For Go projects, we set the GOPATH
export GOROOT="/usr/local/go"
export GOPATH="/Users/joe/Projects/Private/go-projects"
export GODEPS="/Users/joe/Projects/Private/go-projects/bin/godep"
Now I import one of the Go project into IntelliJ and I get to see the following error saying that it is not able to resolve a directory as it can be seen in the screenshot below!
How can I get rid of this error? Any ideas?
I just realized that when I clone the project, I should not do a git clone but rather do:
go get -u github.com/golang/lint/golint
Not sure why this is so, but after doing this my IntelliJ was able to resolve every file on my project!
For golang projects, it's good to have Goland installed ( also a product of JetBrains )Goland Download. Moreover for the above concern you can use:
go get *the_project_to_clone*
I have recently upgraded my Ubuntu from 14.04 to 16.04 and started getting the following error when running any mvn commands (version 3.3.9): Error: Could not find or load main class .usr.share.maven.boot.plexus-classworlds-2.x.jar. My environment variables are declared as follows:
$JAVA_HOME: /usr/lib/jvm/java-8-oracle
$PATH: /usr/local/texlive/2015/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$M2_HOME: /usr/share/maven
$M2: /usr/share/maven/bin
When trying to find a solution, I've tried removing the M2 and M2_HOME variables as suggested on various threads, which resulted in getting a different error: Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher. I have also tried running apt-get remove --purge maven and installing it again as well as downloading the .tar.gz archive, but in both cases, nothing has changed.
When looking into the /usr/share/maven/boot folder, there is a chain of symlinks pointing from plexus-classworlds-2.x.jar -> /usr/share/java/plexus-classworlds2-2.5.2.jar. Am I missing some dependencies? Or are there any old configuration files that did not get removed by --purge?
EDIT: When I execute mvn as root, I get the Launcher error instead of plexus-classworlds-2.x. Also, I have completely removed and reinstalled all plexus libraries, yet with no change.
Check if /usr/share/maven/boot has multiple jars with pattern /usr/share/maven/boot/plexus-classworlds-*.jar.
Mine was something like:
drwxr-xr-x 2 root root 4096 Dec 23 14:21 ./
drwxr-xr-x 6 root root 4096 Nov 14 2015 ../
-rw-r--r-- 1 root root 52684 Dec 12 2015 plexus-classworlds-2.5.2.jar
lrwxrwxrwx 1 root root 34 Dec 10 2015 plexus-classworlds-2.x.jar -> ../../java/plexus-classworlds2.jar
This messes up /usr/share/maven/bin/mvn bash script and executes a wrong java command.
I had to remove the jar and leave only the symbolic link.
I have a Bamboo instance setup to do builds with the following config:
Bamboo version = 3.0.1
when running the build, i got the following error:
09-Mar-2011 08:57:50 Pulling from repository `/root/POC/PRS' to directory '/root/bamboo-ci/xml-data/build-dir/_hg-repositories-cache/d20373e808a2d0e95a604129054231a0da36ff99'
09-Mar-2011 08:57:50 pulling from /root/POC/PRAEFECTUS
09-Mar-2011 08:57:50 searching for changes
09-Mar-2011 08:57:50 no changes found
09-Mar-2011 08:57:50 Copying repository from cache directory to source directory...
09-Mar-2011 08:57:50 Creating empty repository in directory '/root/bamboo-ci/xml-data/build-dir/PRQA-PRQAKEY-JOB1'
09-Mar-2011 08:57:50 Pulling from repository `/root/bamboo-ci/xml-data/build-dir/_hg-repositories-cache/d20373e808a2d0e95a604129054231a0da36ff99' to directory '/root/bamboo-ci/xml-data/build-dir/PRQA-PRQAKEY-JOB1'
09-Mar-2011 08:57:51 pulling from /root/bamboo-ci/xml-data/build-dir/_hg-repositories-cache/d20373e808a2d0e95a604129054231a0da36ff99
09-Mar-2011 08:57:51 requesting all changes
09-Mar-2011 08:57:51 adding changesets
09-Mar-2011 08:57:51 adding manifests
09-Mar-2011 08:57:51 adding file changes
09-Mar-2011 08:57:51 added 1 changesets with 810 changes to 810 files
09-Mar-2011 08:57:51 (run 'hg update' to get a working copy)
09-Mar-2011 08:57:52 810 files updated, 0 files merged, 0 files removed, 0 files unresolved
09-Mar-2011 08:57:52 Updated source code to revision: cc40b2d9c09ea747529887dd8db9319f53c5db4e
09-Mar-2011 08:57:52 Executing build PRQA-PRQAKEY-JOB1-2
09-Mar-2011 08:57:52 Running pre-build action: Build Number Stamper
09-Mar-2011 08:57:52 Running pre-build action: Clover Grails PreBuild Action
09-Mar-2011 08:57:52 Running pre-build action: VCS Version Collector
09-Mar-2011 08:57:52 Running pre-build action: Repository Isolation Enabler Action
09-Mar-2011 08:57:52 Running pre-build action: Maven Settings Prebuild Action
09-Mar-2011 08:57:52 Building started with ScriptBuilder
09-Mar-2011 08:57:52
Starting to build 'PRAEFECTUS-QA - PRQA-PLAN - Default Job'
... running command line: /bin/sh Makefile
... in : /root/bamboo-ci/xml-data/build-dir/PRQA-PRQAKEY-JOB1
09-Mar-2011 08:57:52 Makefile: 10: PYTHON: not found
but if we look at the folder listed in the error, the Makefile is there
root#bambooserver:~/bamboo-ci/xml-data/build-dir/PRQA-PRQAKEY-JOB1# ls -l
total 104
-rw-r--r-- 1 root root 45 2011-03-09 08:57 AUTHORS
drwxr-xr-x 2 root root 4096 2011-03-09 08:57 bin
-rw-r--r-- 1 root root 138 2011-03-09 08:57 build-number.txt
-rw-r--r-- 1 root root 120 2011-03-09 08:57 CHANGES
-rwxr-xr-x 1 root root 9703 2011-03-09 08:57 ez_setup.py
drwxr-xr-x 2 root root 4096 2011-03-09 08:57 images
drwxr-xr-x 2 root root 4096 2011-03-09 08:57 init.d
drwxr-xr-x 5 root root 4096 2011-03-09 08:57 iped
drwxr-xr-x 2 root root 4096 2011-03-09 08:57 logrotate.d
-rw-r--r-- 1 root root 932 2011-03-09 08:57 Makefile
-rw-r--r-- 1 root root 175 2011-03-09 08:57 MANIFEST.in
drwxr-xr-x 2 root root 4096 2011-03-09 08:57 nbproject
-rw-r--r-- 1 root root 1109 2011-03-09 08:57 NEWS
drwxr-xr-x 5 root root 4096 2011-03-09 08:57 prs
drwxr-xr-x 3 root root 4096 2011-03-09 08:57 rpa
drwxr-xr-x 2 root root 4096 2011-03-09 08:57 sbin
drwxr-xr-x 4 root root 4096 2011-03-09 08:57 scripts
-rw-r--r-- 1 root root 81 2011-03-09 08:57 setup.cfg
-rwxr-xr-x 1 root root 2796 2011-03-09 08:57 setup.py
drwxr-xr-x 2 root root 4096 2011-03-09 08:57 src
drwxr-xr-x 7 root root 4096 2011-03-09 08:57 test
drwxr-xr-x 5 root root 4096 2011-03-09 08:57 tests
-rw-r--r-- 1 root root 501 2011-03-09 08:57 TODO
-rw-r--r-- 1 root root 6 2011-03-09 08:57 VERSION
root#bambooserver:~/bamboo-ci/xml-data/build-dir/PRQA-PRQAKEY-JOB1#
any tips on how to setup a Job in Bamboo ? i am using Mercurial and project is in Python.
As I can see you've used a ScriptBuilder which is dedicated to running a shell script while you probably need a builder that runs a command
make
What you need to do is:
go to Administration / Server Capabilities
in "Add Capability" select: Capability Type: Builder, Type: Command, Builder Label: Make, Path: enter the full path to your make utility (ie. /usr/bin/make)
now navigate to your plan configuration and change the builder to "Make"
After those changes your build should be working fine.
PS.
In case of future problems you should try reporting the problem on Atlassian's support site (http://support.atlassian.com)
Disclaimer: yes I work for Atlassian