I created a Go container using Visual Studio Code remote containers extensions.
The project structure is like this:
archy-go
├── .devcontainer
│ ├── devcontainer.json
│ └── Dockerfile
└── src
└── git.mycompany.com
├── main.go
└── mycompany
└── archy-go
└── cmd
├── createBackend.go
├── createFull.go
├── create.go
├── root.go
├── say.go
└── sayhello.go
But when I try the command go build inside the git.mycompany.com folder I get an error like this:
root#b570cd82e7e5:/workspaces/archy-go/src/git.mycompany.com# go build
main.go:3:8: cannot find package "git.mycompany.com/mycompany/archy-go/cmd" in any of:
/usr/local/go/src/git.mycompany.com/mycompany/archy-go/cmd (from $GOROOT)
/go/src/git.mycompany.com/mycompany/archy-go/cmd (from $GOPATH)
What did I do wrong? Or what is the correct way to set up GOPATH in this situation?
Related
This is my project file structure:
java-project/
├── docker.compose.yml
├── pom.xml
└── services/
├── a/
│ ├── Dockerfile
│ ├── pom.xml
│ ├── src/
│ │ ├── pom.xml
│ │ ├── xxx
│ │ └── xxx
│ └── target/
│ ├── pom.xml
│ └── xxxx
└── b/
├── Dockerfile
├── pom.xml
├── src/
│ ├── pom.xml
│ ├── xxx
│ └── xxx
└── target/
├── pom.xml
└── xxxx
I want to copy all of the contents of the services folder of the project (including all the subfolders inside the services). Basically, I want to replicate the current project structure with every file and folder in the docker image as well for the mvn build to execute successfully.
I am doing the following in the Dockerfile, but I don't see all of the contents:
COPY services/**/pom.xml ./services/
What am I doing wrong here? TIA
Let's look at your COPY instruction:
# <src> <dest>
COPY services/**/pom.xml ./services/
Under the hood, Docker reads the <src> using Go's filepath.Match method. This means that the instruction doesn't use the globstar (**) the way glob patterns do. However, your question suggests you want to copy everything inside services — not only pom.xml files.
You can copy everything inside your local services directory using:
COPY services ./services/
If you want to exclude certain subdirectories or files, you can specify this using a .dockerignore.
I have a project including multiple Dockerfiles.
The tree is like,
.
├── app1
│ ├── Dockerfile
│ ├── app.py
│ └── huge_modules/
├── app2
│ ├── Dockerfile
│ ├── app.py
│ └── huge_modules/
├── common
│ └── my_lib.py
└── deploy.sh
To build my application, common/ is necessary and we have to COPY it inside Dockerfile.
However, Dockerfile cannot afford to COPY files from its parent directory.
To be precise, it is possible if we run docker build with -f option in the project root.
But I would not like to do this because the build context will be unnecessarily large.
When building app1, I don't like to include app2/huge_modules/ in the build context (the same as when building app2).
So, I prepare a build script in each app directory.
Like this.
cd $(dirname $0)
cp ../common/* ./
docker build -t app1 .
But this solution seems ugly to me.
Is there a good solution for this case?
Build a base image containing your common library, and then build your two app images on top of that. You'll probably end up restructuring things slightly to provide a Dockerfile for your common files:
.
├── app1
│ ├── Dockerfile
│ ├── app.py
│ └── huge_modules/
├── app2
│ ├── Dockerfile
│ ├── app.py
│ └── huge_modules/
├── base
| ├── Dockerfile
| └── common
│ └── my_lib.py
└── deploy.sh
You start by building a base image:
docker build -t mybaseimage base/
And then your Dockerfile for app1 and app2 would start with:
FROM mybaseimage
One possible solution is to start the build process from the top directory, with the -f flag you mentioned, dynamically generating the .dockerignore file.
That is, lets say that you currently build app1. Then you would first create in the top directory a .dockerignore file with the content: app2, then run the build process. After finishing the build, remove the .dockerignore file.
Now you want to build app2? No problem! Similarly generate first dynamically a .dockerignore file with the content app1, build and remove the file. Voila!
I need to compile a Golang application for Linux and I can't cross-compile under Mac, because of another library. So I decided to compile within a Docker container. This is my first time to use Docker.
This is my current directory structure:
.
├── Dockerfile
├── Gopkg.lock
├── Gopkg.toml
├── Vagrantfile
├── bootstrap.sh
├── src
│ ├── cmd
│ │ ├── build.bat
│ │ ├── build.sh
│ │ ├── config.json
│ │ ├── readme.md
│ │ └── server.go
│ ├── consumers.go
│ ├── endpoints
│ │ ├── json.go
│ │ ├── rate.go
│ │ ├── test_payment.go
│ │ └── wallet.go
│ ├── middleware
│ │ └── acl.go
│ ├── models.go
│ ├── network
│ │ └── network.go
│ ├── qr
│ │ └── qr.go
│ ├── router
│ │ └── router.go
│ ├── service
│ │ └── walletService.go
│ ├── services.go
│ ├── setup.sql
│ ├── store
│ │ └── wallet.go
│ ├── stores.go
│ └── wallet
│ ├── coin.go
│ └── ethereum.go
Dockerfile:
FROM golang:latest
WORKDIR /src/cmd
RUN ls
RUN go get github.com/go-sql-driver/mysql
RUN go build -o main ./src/cmd/server.go
CMD ["./main"]
I try to build the Docker image with:
docker build -t outyet .
This is the error it returns:
Sending build context to Docker daemon 5.505MB
Step 1/6 : FROM golang:latest
---> d0e7a411e3da
Step 2/6 : WORKDIR /src/cmd
---> Using cache
---> 0c4c2b99e294
Step 3/6 : run ls
---> Using cache
---> 23d3e491a2e1
Step 4/6 : RUN go get github.com/go-sql-driver/mysql
---> Running in f34447e51f6c
Removing intermediate container f34447e51f6c
---> 5731ab22ee43
Step 5/6 : RUN go build -o main server.go
---> Running in ecc48fcf5488
stat server.go: no such file or directory
The command '/bin/sh -c go build -o main server.go' returned a non-zero code: 1
How i can build my Golang application with docker?
The error you're seeing is:
stat server.go: no such file or directory
The command '/bin/sh -c go build -o main server.go' returned a non-zero code: 1
... and in other words, it's telling you that the Go compiler can't find server.go which you're trying to build. Update your Dockerfile to copy your local files into the Docker image:
FROM golang:latest
COPY . /go/src/workdir
WORKDIR /go/src/workdir
RUN go build -o main ./src/cmd/server.go
CMD ["/go/src/workdir/main"]
In your directory I spotted Gopkg.toml which is a dependency manifest used by dep. dep will use a directory called vendor to include all dependencies for your Go project. Before you build the Docker image, you need to ensure all dependencies are present with dep ensure:
$ dep ensure
$ docker build -t outyet .
You need to add your sources in your build container. Add this line in your Dockerfile (after FROM golang:latest for example) :
ADD src/ /src/cmd
Then, you could access files inside the container (/src/cmd) : RUN ls should now return something.
I have a repo with a client and a server respectively based on NodeJs/Angular2 and Python/Django with approximately this folder structure:
main/
├── angular2-client/
│ ├── build/
│ ├── dist/
│ ├── node_modules/
│ ├── src/
│ └── ...
└── django-server/
├── myapp/
├── server/
├── manage.py
└── ...
So, client and server are both on the same repo and same branch. What's the correct way of setting up Travis to build/deploy client and server to 2 different providers (eg. Firebase and AWS)?
Any suggestion, documentation reference or tutorial is highly appreciated.
Thanks
I am unable to run gulp images.
This is what I have installed on my computer:
├── async#0.9.2
├── bower#1.3.12
├── browser-sync#2.1.6
├── chai#1.10.0
├── colors#1.1.2
├── glob#4.5.3
├── glob-all#3.0.1
├── gulp#3.9.0
├── gulp-changed#1.3.0
├── gulp-clean#0.3.1
├── gulp-compass#2.0.4
├── gulp-concat#2.5.2
├── gulp-flatten#0.0.4
├── gulp-gm#0.0.7
├── gulp-jsonminify#1.0.0
├── gulp-plumber#0.6.6
├── gulp-rename#1.2.2
├── gulp-template-compile#0.2.1
├── gulp-uglifyjs#0.6.2
├── imagemin-jpegoptim#4.0.0
├── imagemin-optipng#4.3.0
├── imagemin-pngquant#4.2.0
├── js-yaml#3.4.2
├── lodash#3.10.1
├── merge-stream#0.1.8
├── mocha#2.3.2
├── run-sequence#1.0.2
└── should#4.6.5
And this is the error that gets flagged when I run gulp images:
Invalid image: /###/card/6997479627_922084ec63-card.jpg
[11:54:10] Plumber found unhandled error:
Error in plugin 'gulp-gm'
I've tried uninstalling and reinstalling gulp, graphicsmagick, and imagemagick but it still flags the error.
Thanks for your help
I would install the latest version of gulp-gm, image manipulation with GraphicsMagick for gulp.