AWS CodeBuild directory issues? - amazon-web-services

Using the stock CodeBuild Ubuntu14.04 base image.
Anyone else experiencing odd behavior with directories? Commands like "pushd" do not exist. You start out in this weird "/tmp/src200838814/src" directory. The cd command seems wonky too.
Really hard when you are trying to run cmake.

The way AWS CodeBuild works is that each command is executed in the base directory. For your case all commands will be executed in "/tmp/src200838814/src". If you would like to execute commands in a different directory you will have to chain a single command to move you then execute for example.
cd other-dir && cmake
Let me know if you have any other questions.

Did you try with this env CODEBUILD_SRC_DIR?
I always cd to this one before executing anything to make sure I know what is my current directory.
cd ${CODEBUILD_SRC_DIR}

Related

Gitlab CI doesn't behave as expected when c++ program changes directory

let's assume in my code there is a system process to do. However, i have to change directory before doing so and the going back, that step is necessary, no simple way to circumvent this operation.
std::filesystem::current_directory("child/");
std::process::system(command);
std::filesystem::current_directory("../");
This works in my local machine, however, in my gitlab-ci runner, which runs in the same relative path as in local, it seems that is incapable of changing the current directory, and runs the command in the directory the script was placed:
testing:
stage: testing
image:
#same OS and similar environment as local
name: myhub/archlinux
script:
- export BOOST_INCLUDEDIR="/usr/include/boost/"
- export BOOST_LIBRARYDIR="/usr/lib/"
- cd build/tests
- ./buildUStests
Is there a way to tell the runner to be more flexible when the program demands to change the current directory? Or do i have to use another way to make the runner change directories?
Sorry for the confusion, I actually found the issue.
GitLab and git essentially don't incorporate empty directories, which my program relies on, into my repo.
This means that if I roll my tests without knowing that behavior, it seems as if my program refuses to change directory.
The solution to the problem is to create the directory at execution, then make the shell commands.

Github Actions path does not update

Right now, I'm trying to build a tool from source and use it to build a C++ project. I'm able to extract the tar file (gcc-arm-none-eabi). But, when I try to add it to path (using $GITHUB_PATH, not add-path), the path doesn't apply on my next action and I can't build the file. The error states that it can't find the gcc-arm-none-eabi toolset, which means that it didn't go to path.
Here's the script for the entrypoint of the first function (make is ran in the next action to allow for path to apply)
echo "Downloading ARM Toolchain"
# The one from apt isn't updated so I have to build from source
curl -L https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -o gcc-arm-none-eabi.tar.bz2
tar -xjf gcc-arm-none-eabi.tar.bz2
echo "/github/workspace/gcc-arm-none-eabi-10-2020-q4-major/bin" >> $GITHUB_PATH
I can't even debug by seeing what's in the path because running echo $(PATH) just says that PATH cannot be found. What should I do?
I can't even debug by seeing what's in the path because running echo $(PATH) just says that PATH cannot be found. What should I do?
First, PATH is not a command so if you want to print its value, it would be something like echo "${PATH}" or echo "$PATH"
Then, if you want to add a value to an existing environment variable, it would be something like
export PATH="${PATH}:/github/workspace/gcc-arm-none-eabi-10-2020-q4-major/bin"
EDIT: seems not a valid way to add something to the path using Github Actions, meanwhile it seems correct in the question. To get more details: https://docs.github.com/en/free-pro-team#latest/actions/reference/workflow-commands-for-github-actions#adding-a-system-path . Thanks to Benjamin W. for pointing this out in the comments.
Finally I think it would be a better fit if you use a docker image that already contains that kind of dependancies (you could easily write your own Dockerfile if this image doesn't already exists). Github action is designed to use docker (or OCI containers) image that contains the dependancies you need to perform your build actions. You should take a look here: https://docs.github.com/en/free-pro-team#latest/actions/creating-actions/dockerfile-support-for-github-actions

Making c++ app use directory of file, not pwd

I am trying to run an application, app. I do this by running ./app in the directory of app. This application has a dependency, graphics/file.bmp. Everything works when I run ./app in that directory.
If I instead run from the parent folder, it can't find graphics/file.bmp when I run ./app_directory/app
What is the cleanest way to resolve this? I would like to cd into the directory of the file no matter where I am running the program from. I am on OSX and would be thrilled by a solution that works across all unix machines.
You can do this on the first line of main():
chdir(dirname(argv[0]));
dirname() removes the last path component from the input ("a/b/c" turns into "a/b") and if there is only one path component then it returns ".". Passing this return value directly into chdir() will change the working directory to the directory containing the binary.
You could try writing a bash script that you could run from any directory and it will cd into the directory that successfully runs the program, but this won't actually change the working directory at which your terminal is sitting. In case you don't know how to do that: make a file called build (or whatever you want) and place it in the parent folder. In that file put the following code:
cd app_directory
./app
After you create the script run chmod u+x <script-name>, which will make it an executable. Once this is done you can just run ./<script-name> and it should run your program just fine.

How to create any customized Unix command?

I want to create one unix command, which will unzip the folder.
so, I am searching for the code, but I am not aware that how should I use such code to make Unix command?
I have gone through various questions & answers but I don't get any perfect information.
So, can any one please suggest me any code (in C++ or C or any language to make exe) and to use it as a Unix command.
NOTE: I know command like 'unzip' is available in 'Mks toolkit' type of software but we can not use it, so I want to make command which can run through 'command prompt'
If you want to add a command, you only need to create your executable and put its link in the /usr/bin folder.
Just compile your code and set a link to it's executable like this:
ln -s /path/to/your_executable /usr/bin/command_name
If there exists a command that you need to modify, you should set an alias to it. For example, you want ls -1 to run whenever ls is used, then you only need to use the command:
alias ls=ls -1
or put the same command in the .bashrc file in your home directory.

Using %{buildroot} in a SPEC file

I'm creating a simple RPM installer, I just have to copy files to a directory structure I create in the %install process.
The %install process is fine, I create the following folder /opt/company/application/ with the command mkdir -p %{buildroot}/opt/company/%{name} and then I proceed to copy the files and subdirectories from my package. I've tried to install it and it works.
The doubt I have comes when uninstalling. I want to remove the folder /opt/company/application/ and I thought you're supposed to use %{buildroot} anywhere when referencing the install location. Because my understanding is the user might have a different structure and you can't assume that rmdir /opt/company/%{name}/ will work. Using that command in the %postun section deletes succesfully the directories whereas using rmdir ${buildroot}/opt/company/%{name} doesn't delete the folders.
My question is, shouldn't you be using ${buildroot} in the %postun in order to get the proper install location? If that's not the case, why?
Don't worry about it. If you claim the directory as your own in the %files section, RPM will handle it for you.
FYI, %{buildroot} probably won't exist on the target machine.