AWS local build (CodeBuild) pass credentials file with wsl2 - docker

I upgraded my docker desktop to the version 3.2.1 (61626), and choose to use wsl2, after that i cannot run Local builds of AWS CodeBuild because the AWS configuration is not being found, the command I use is (I run the command from a tab from Windows terminal using ubuntu 20 that I installed from the store):
./codebuild_build.sh -i aws/codebuild/standard:5.0 -a ./ -s ./ -b ./buildspec.yml -c ~/.aws
That command works with the version of docker that uses Hyper-V, after the upgrade to wsl2 i get the error:
agent_1 | [Container] 2021/03/05 21:04:05 Phase complete: DOWNLOAD_SOURCE State: FAILED
agent_1 | [Container] 2021/03/05 21:04:05 Phase context status code: Decrypted Variables Error Message: MissingRegion: could not find region configuration
The docker command that is generated is the following:
docker run -it -v /var/run/docker.sock:/var/run/docker.sock -e "IMAGE_NAME=aws/codebuild/standard:5.0" -e "ARTIFACTS=/mnt/c/[redacted]" -e "SOURCE=/mnt/c/[redacted]" -e "BUILDSPEC=/mnt/c/[redacted]" -e "AWS_CONFIGURATION=NONE" -e "INITIATOR=[redacted]" amazon/aws-codebuild-local:latest
edit:
running the command from git bash the generated command is:
winpty docker run -it -v //var/run/docker.sock:/var/run/docker.sock -e "IMAGE_NAME=aws/codebuild/standard:5.0" -e "ARTIFACTS=//C/[redacted]" -e "SOURCE=//C/[redacted]" -e "BUILDSPEC=//C/[redacted]" -e "AWS_CONFIGURATION=//C/Users/[redacted]/.aws" -e "INITIATOR=[redacted]" amazon/aws-codebuild-local:latest
But also fails with the error:
agent_1 | [Container] 2021/03/05 22:17:43 Phase complete: DOWNLOAD_SOURCE State: FAILED
agent_1 | [Container] 2021/03/05 22:17:43 Phase context status code: YAML_FILE_ERROR Message: stat /codebuild/output/srcDownload/src/buildspec.pr.yml: no such file or directory
With the previous command the variable AWS_CONFIGURATION had the path to my .aws folder, I had tried -c //c/Users/[myProfile]/.aws and /mnt/c/Users/[myProfile]/.aws but AWS_CONFIGURATION is always NONE
Is there a configuration that I'm missing? or I need add an extra step with wsl2?
Edit:
I installed Ubuntu 18 and failed in the same way.

I was having a similar problem. I realized that since I had to run docker as root using the sudo command, my home directory was now /root instead of /home/<username>.
There may be a better way around this, but I symlinked the folder /home/<username>/.aws to /root/.aws.
Also, you could pass the variables AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, and AWS_ACCESS_KEY_ID in through an environment file using the -e flag of the codebuild_build.shcommand.

Related

how to set docker so that terragrunt binary executes properly

This command allows me to execute terragrunt binary within a docker cintainer correctly:
$ docker run -ti --rm -v $HOME/.aws:/root/.aws -v ${HOME}/.ssh:/root/.ssh -v `pwd`:/apps -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN alpine/terragrunt:0.13.6 bash
I simply have to cd into the directory where the terragrunt config file can be found, and execute the command:
bash-5.0# cd environments/assembly/us-east-1/sqs/ss-error-generic-encrypted/core/
bash-5.0# terragrunt init -reconfigure;terragrunt plan
(this is happening within the docker container shell)
And it works perfectly. However, I need to create a method of executing this from a script (like a Jenkins job), not interactively. So I tried this:
$ docker run -ti --rm -v $HOME/.aws:/root/.aws -v ${HOME}/.ssh:/root/.ssh -v `pwd`:/apps -w /apps/environments/assembly/us-east-1/sqs/ss-error-generic-encrypted/core -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN alpine/terragrunt:0.13.6 terragrunt init -reconfigure; terragrunt plan
The error I see seems like the -w doesn't work the way I think it works:
[terragrunt] 2022/08/27 11:12:14 Error reading file at path /Users/chewmanfoo/bitbucket.org/aws-terraform-infrastructure/terragrunt.hcl: open /Users/chewmanfoo/bitbucket.org/aws-terraform-infrastructure/terragrunt.hcl: no such file or directory
I thought the -w /apps/environments/assembly/us-east-1/sqs/ss-error-generic-encrypted/core would set the working directory to that path within the container, so that I could execute the binary in the proper place. But it seems to be doing something else.
Can anyone lend your expertise?

How to run commands in Docker container

Hello I m trying to follow the step by step guid to build jpeg xl (I m on windows and try to build a x64 version for linux)
after:
docker run -u root:root -it --rm -v C:\Users\fred\source\tools\jpegxl\jpeg-xl-master -w /jpeg-xl gcr.io/jpegxl/jpegxl-builder
I have the container running but I don't know how to run the command inside :
CC=clang-6.0 CXX=clang++-6.0 ./ci.sh opt
I tried CC=clang-6.0 CXX=clang++-6.0 ./ci.sh opt and I get ./ci.sh: No such file or directory no command seems to work when I do "ls" it display nothing
Does someone knows how to get this to build?
Make sure that you start a bash terminal inside the container:
docker run -it <image> /bin/bash
I believe /bin/bash is missing from your docker run command. As a result, you are executing the command for clang inside your own environment, not the container.
You can set the environment variables by using -e
Example
-e CC=clang-6.0 -e CXX=clang++-6.0
The full command to log in into your container:
docker run -u root:root -it --rm -e CC=clang-6.0 -e CXX=clang++-6.0 -v C:\Users\fred\source\tools\jpegxl\jpeg-xl-master -w /jpeg-xl gcr.io/jpegxl/jpegxl-builder /bin/bash
They have updated the image without updating the command so the command is
CC=clang-7 CXX=clang++-7 ./ci.sh opt
The discution is here:
Can't build from docker image "Unknown clang version"

Executing a script inside a docker container gives no errors but does not work either

I have a docker container with the basic ubuntu image. I use the following command to start it.
docker container run -it -d -v c:\Git\ENGINE_LIB_DIR:/ENGINE_LIB_DIR:ro --name ibuntu ubuntu
inside the mounted volume is a Java JDK and a script which looks like this:
#!/bin/bash
echo "export JAVA_HOME=/ENGINE_LIB_DIR/jdk/" >> ~/.bashrc;
echo "export PATH=${PATH}:/ENGINE_LIB_DIR/jdk/bin/" >> ~/.bashrc;
exec bash
So it basically adds the mounted java to the path to make it useable. This script works, as long as I am executing it from the ubuntu bash inside the container. If I try to use
docker exec -it ibuntu sh -c "sh /ENGINE_LIB_DIR/action.sh"
from outside the container it does not give any error message, whereas
docker exec -it ibuntu sh -c "java -version"
Returns "java: not found". So I suspect the script is not executed properly. I tried absolute paths, just without "sh -c" and basically any other method I found by googeling.
My goal is to easily use a java jdk provided inside a docker container to build a project. I am gladful for any help.
Edit:
I tried the /bin/bash -ic approach from #itachi. It still says java: not found, while the shell call gives back that error:
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
sh: 0: Can't open ./ENGINE_LIB_DIR/action.sh
Edit 2:
I managed to narrow the behaviour down to the docker exec command. I setup the container with docker container run -it -d -v c:\Git\ENGINE_LIB_DIR:/ENGINE_LIB_DIR:ro --entrypoint /ENGINE_LIB_DIR/action.sh --name ibuntu ubuntu /bin/bash. The java path variable is functioning when attached to the container, but when i execute docker exec ibuntu sh -c "java -version" it still says sh: 1: java: not found. I would be grateful for any idea.

Error when trying to create container with mounted volume

I'm trying to mount a volume on a container so that I can access files on the server I'm running the container. Using the command
docker run -i -t 188b2a20dfbf -v /home/user/shared_files:/data ubuntu /bin/bash
results in the error
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:296: starting container process caused "exec: \"-v\":
executable file not found in $PATH": unknown.
I'm not sure what to do here. Basically, I need to be able to access a script and some data files from the host server.
The docker command line is order sensitive. After the image name, everything passed is a command that runs inside the container. For docker, the first thing that doesn't match an expected argument after the run command is assumed to be the image name:
docker run -i -t 188b2a20dfbf -v /home/user/shared_files:/data ubuntu /bin/bash
That tries to run a -v command inside your image 188b2a20dfbf because -t takes no value.
docker run -i -t -v /home/user/shared_files:/data 188b2a20dfbf /bin/bash
That would run bash in that same image 188b2a20dfbf.
If you wanted to run your command inside ubuntu instead (it's not clear from your example which you were trying to do), then remove the 188b2a20dfbf image name from the command:
docker run -i -t -v /home/user/shared_files:/data ubuntu /bin/bash
Apparently, on line 296 on your .go script you is referring to something that can't be found. Check your environment variables to see if they contain the path to that file, if the file is included in the volume at all, etc.
188b2a20dfbf passed to -t is not right. -t is used to get a pseudo-TTY terminal for the container:
$ docker run --help
...
-t, --tty Allocate a pseudo-TTY
Run docker run -i -t -v /home/user/shared_files:/data ubuntu /bin/bash. It works for me:
$ echo "test123" > shared_files
$ docker run -i -t -v $(pwd)/shared_files:/data ubuntu /bin/bash
root#4b426995e373:/# cat /data
test123

How to take Oracle-xe-11g backup from running Docker container

I am running oracle-xe-11g on rancher os. I want to take the data backup of my DB. When I tried with the command
docker exec -it $Container_Name /bin/bash
then I entered:
exp userid=username/password file=test.dmp
It is working fine, and it created the test.dump file.
But I want to run the command with the docker exec command itself. When I tried this command:
docker exec $Container_Name sh -C exp userid=username/password file=test.dmp
I am getting this error message: sh: 0: Can't open exp.
The problem is:
When running bash with -c switch it is not running as interactive or a login shell so bash won't read the same startup scripts. Anything set in /etc/profile, ~/.bash_profile, ~/.bash_login, or ~/.profile would be skipped.
Workaround:
run your container with following command:
sudo docker run -d --name Oracle-DB -p 49160:22 -p 1521:1521 -e ORACLE_ALLOW_REMOTE=true -e ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe -e PATH=/u01/app/oracle/product/11.2.0/xe/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -e ORACLE_SID=XE -e SHLVL=1 wnameless/oracle-xe-11g
What I'm doing is specifying the environment variables set in the container using docker.
Now for generating the backup file:
sudo docker exec -it e0e6a0d3e6a9 /bin/bash -c "exp userid=system/oracle file=/test.dmp"
Please note the file will be created inside the container, so you need to copy it to docker host via docker cp command
This is how I did it. Mount a volume to the container e.g. /share/backups/ then execute:
docker exec -it oracle /bin/bash -c "ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe ORACLE_SID=XE /u01/app/oracle/product/11.2.0/xe/bin/exp userid=<username>/<password> owner=<owner> file=/share/backups/$(date +"%Y%m%d")_backup.dmp"

Resources