Inconsistent Script Execution [closed] - laravel

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 days ago.
Improve this question
I've created the following script to loop through my Laravel pacakges, run containers, run tests and stop containers:
testAll () {
dir=~/packages;
for f in "$dir"/*
do
cd $f;
sail down;
done;
for f in "$dir"/*
do
cd $f;
sail up;
migrate;
testAll;
sail down;
done;
cd ..;
}
migrate () {
if [ ! -z $(docker ps --filter expose=3306 --format "{{.ID}}") ];
then
sail artisan migrate:fresh --seed;
fi
}
When I run testAll command, it works as it should do until it needs migrations. I'm getting this error:
SQLSTATE[HY000] [2002] Connection refused (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
But when I execute migrate script by typing it to console, it works. I don't know what causes this inconsistent behaviour. Can anyone help?
Thanks in advance.

Related

Laravel Sail "build path ./vendor/laravel/sail/runtimes/8.0 either does not exist, is not accessible, or is not a valid URL."

I'm using Laravel 8.x with Sail using PHP 8.0, recently, I actually messed up my compose.json file resulting in issues with the vendor, trying to recreate the project from scratch, I deleted the vendor folder.
Normally, docker-compose would build and create the /path/to/project/vendor/laravel/sail/runtimes/ directory with its appropriate content, but for some reason, I keep getting the following error:
ERROR: build path /path/to/project/vendor/laravel/sail/runtimes/8.0 either does not exist, is not accessible, or is not a valid URL.
I tried using docker system prune and deleting the existing containers manually through the Docker Desktop interface, and I even tried running it with docker-compose build --no-cache, I still get the same error.
Is there a way to fix this or should I just clone my project again and try to build it?
Note: I'm using an old Mac without the possibility of just manually running composer install so any of my interactions with the instance relies on the docker container working.
docker run --rm --interactive --tty --volume C:/path/to/project:/app composer install --ignore-platform-reqs --no-scripts
The standard procedure for setting up any Laravel project should be running composer install, so an inability to do so really ties one's hands here.
However, in this case, where the only way for me to run composer was through docker, I elected to use the laravel.build website to create a new project and copy the vendor folder over. Here's the script:
docker info > /dev/null 2>&1
# Ensure that Docker is running...
if [ $? -ne 0 ]; then
echo "Docker is not running."
exit 1
fi
docker run --rm \
-v $(pwd):/opt \
-w /opt \
laravelsail/php80-composer:latest \
bash -c "laravel new example-app && cd example-app && php ./artisan sail:install --with=mysql,redis,meilisearch,mailhog,selenium"
cd example-app
CYAN='\033[0;36m'
LIGHT_CYAN='\033[1;36m'
WHITE='\033[1;37m'
NC='\033[0m'
echo ""
if sudo -n true 2>/dev/null; then
sudo chown -R $USER: .
echo -e "${WHITE}Get started with:${NC} cd example-app && ./vendor/bin/sail up"
else
echo -e "${WHITE}Please provide your password so we can make some final adjustments to your application's permissions.${NC}"
echo ""
sudo chown -R $USER: .
echo ""
echo -e "${WHITE}Thank you! We hope you build something incredible. Dive in with:${NC} cd example-app && ./vendor/bin/sail up"
fi
After that, running ./vendor/bin/sail up -d && ./vendor/bin/sail composer install fixed the problem.

Changing user in docker container changes bash settings [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I'm experiencing this behavior:
I have a docker image:
FROM ubuntu:latest
...
RUN useradd -m develop
USER develop
When I run the container:
docker run -it my_image
I get a terminal with all the features such as LS_COLORS, completion of files/directories names with TAB, etc. But if I run the container with root user:
docker run -it -u 0 my_image
And then, in the container:
~$ su develop
Now my prompt doesn't havae any of the above features, and is very hard to work with. Can someone explain this behavior? I assume it has something to do with all the initialization scripts such as .bashrc, /etc/profile, etc., but I don't quite understand the difference between the two above scenarios.
EDIT
Thanks #ItayB for the answer, I just figured it out also :).
But still, the behavior is not exactly the same as if I would just login as develop:
~$ docker run -it -u 0 build_agent:0.5
root#6acf7b900da3:/# su develop
$ bash
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
bash: /root/.bashrc: Permission denied
develop#6acf7b900da3:/$ cd ~
bash: cd: /root: Permission denied
develop#6acf7b900da3:/$
As you can see, the environment variables are still set as if I was "Root" user. Why is that?
I think you should explicitly call bash after switching user:
$ docker run -it -u 0 my_image
root#74765d85882a:/# su develop
$ bash
develop#74765d85882a:/$

Convert file bat for mac [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
On Windows I use this file bat that allows me to start the artisan application without having to do everything manually every time
cd c:\xampp\htdocs\gamelite-lv
php artisan serve
I tried to replicate the script for Mac, but I can't use it:
#!/bin/bash
cd ..
cd ..
cd Applications
cd mamp
cd htdocs/lv/
php artisan serve
moreover, with the batch for mac, is it possible to create a system of choices like?
#ECHO OFF
:StartLoop
CLS
ECHO 1.Start Laravel
ECHO 2.Update Composer
ECHO 3.Install Composer
ECHO 4.Show Router
ECHO 5.Run SASS
ECHO.
CHOICE /C 12345 /M "Select choice:
I solved that:
PS3='Choise: '
options=("Start Laravel" "Update Composer")
select opt in "${options[#]}"
do
case $opt in
"Start Laravel")
cd /applications/mamp/htdocs/lv
php artisan serve
;;
"Update Composer")
cd /applications/mamp/htdocs/lv
php composer.phar update
;;
*) echo "$REPLY invalid choice";;
esac
done
In order to start the file with a double click I renamed the .command file, and I set the permissions:
chmod ugo+x file

How can I force cancel dockerbuild using bash a command?

The reason why I'm asking is because we're using AWS codebuild & I need to do DB migrations. If a DB migration breaks, I want to cancel the codebuild & rollback the migration which was just made. I've got this part working, all I need to do now is cancel the dockerbuild mid way. How can I do this?
This is my .sh file with the knex migration commands:
#!/bin/bash
echo "running"
function mytest {
"$#"
local status=$?
if [ $status -ne 0 ]; then
knex migrate:rollback
echo "Rolling back knex migrate $1" >&2
exit
fi
return $status
}
mytest knex migrate:latest
Running exit will not cancel/break the docker build.
My Dockerfile (just incase):
FROM node:6.2.0
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
RUN chmod +x /usr/src/app/migrate.sh
RUN /usr/src/app/migrate.sh
EXPOSE 8080
CMD npm run build && npm start
Running exit will not cancel/break the docker build.
running exit 1 should
Docker should respond to the error codes returned by the RUN shell scripts in said Dockerfile.

Mac doesn't boot after running this code [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I know this is kinda off-topic, but since I've found the code I'm talking about here on SO I hope that someone can help me.
I was dealing with a POSTGRES error and read here: Can not connect to local PostgreSQL an answer, the one from vvdpzz that lead me to run that code in my terminal.
After that, my mac stopped working and since then it doens't reboot, it comes till the apple logo that keeps flashing and switching with a folder with a question mark.
I've checked the code that curl execute and it's the following:
#!/bin/sh
BREW_POSTGRES_DIR=`brew info postgres | awk '{print $1"/bin"}' | grep "/postgresql/"`
LION_POSTGRES_DIR=`which postgres | xargs dirname`
LION_PSQL_DIR=`which psql | xargs dirname`
sudo mkdir -p $LION_POSTGRES_DIR/archive
sudo mkdir -p $LION_PSQL_DIR/archive
for i in `ls $BREW_POSTGRES_DIR`
do
if [ -f $LION_POSTGRES_DIR/$i ]
then
sudo mv $LION_POSTGRES_DIR/$i $LION_POSTGRES_DIR/archive/$i
sudo ln -s $BREW_POSTGRES_DIR/$i $LION_POSTGRES_DIR/$i
fi
if [ -f $LION_PSQL_DIR/$i ]
then
sudo mv $LION_PSQL_DIR/$i $LION_PSQL_DIR/archive/$i
sudo ln -s $BREW_POSTGRES_DIR/$i $LION_PSQL_DIR/$i
fi
done
What happened? I'm not an expert. How can I solve this. I've tried to start in secure mode by pressing the shift key while booting but it doesn't work.
This is a good example of why you shouldn't run scripts without understanding what they do. My guess is that one or both of LION_PSQL_DIR and LION_POSTGRES_DIR came out as empty and the script ended up moving things around in your root directory. You should be able to recover your system by following these steps:
Boot your OS X installation disc by putting it in the drive and holding the C key while booting.
From the Utilities menu, choose Terminal
Run the command cd /Volumes
Run the command ls which should show an entry corresponding to the name of your Mac's hard drive
Run the command cd "<name of your hard drive>"
Run the command ls. If the problem is that things got moved from the root of your drive, there will be an archive entry, if there isn't then stop since this will not fix your problem.
Run the command cd archive to enter the archive directory
Run the command mv * .. to move everything in the archive directory back to the root of your harddrive
Close the terminal
Run Disk Utility from the Utilities menu and use repair permissions on your drive.
Reboot your computer and hopefully it will work right now
Never run random scripts like that again.
The 10th step might not be strictly necessary. I haven't tried to do these steps myself, but they should be pretty close to correct. If you get any errors during them stop and put a comment and I will try and figure out how to proceed.

Resources