What is the right way to source .sh file after auto deployment to azure linux webapp? - laravel

I have a laravel application on my azure webapp (linux).
I am trying to run some php commands after deploying.
I am using Local Git to deploy to my azure's webapp.
and as per this guide, i set the "POST_BUILD_SCRIPT_PATH" to run a script named "postbuild.sh"
(Note that i am using a .sh file since i am in a Linux based webapp. )
The problem is my postbuild.sh location is in "wwwroot" (where my laravel root application is).
but i keep getting the
Could not open input file: artisan
message when i try to run any artisan command like
php artisan cache:clear
After looking up, i found that the script is being executed from a tmp location.
and i should use sourcing for running the script in the right location but it is still doesn't work.
so i created another .sh file in 'wwwroot' as well named 'clearcache.sh' and tried to source it in 'postbuild.sh' but still not working.
My postbuild.sh is
echo "Post Build .sh"
echo "Script executed from: ${PWD}"
BASEDIR=$(dirname $0)
echo "Script location: ${BASEDIR}"
echo "===================="
source ./home/site/wwwroot/refresh.sh
My refresh.sh is
echo "Refresh script"
echo "Script executed from: ${PWD}"
BASEDIR=$(dirname $0)
echo "Script location: ${BASEDIR}"
php artisan cache:clear
and the errors i am having when pushing to azure repo is:
remote: Detecting platforms...
remote: Detected following platforms:
remote: php: 7.4.24
remote:
remote: Using intermediate directory '/tmp/8d9a71074a40f5b'.
remote:
remote: Copying files to the intermediate directory...
remote: Done in 0 sec(s).
remote: /home/site/wwwroot/postbuild.sh: line 6: ./home/site/wwwroot/refresh.sh
remote:
remote: : No such file or directory
remote: Source directory : /tmp/8d9a71074a40f5b
remote: Destination directory: /home/site/wwwroot
remote:
remote: Executing pre-build command...
remote: Pre Build
remote: Finished executing pre-build command.
remote: PHP executable: /tmp/oryx/platforms/php/7.4.24/bin/php
remote: No 'composer.json' file found; not running 'composer install'.
remote:
remote: Executing post-build command...
remote: Post Build .sh
remote: Script executed from: /tmp/8d9a71074a40f5b
remote: Script location: /home/site/wwwroot
remote:
remote: ====================
Please note the following:
Laravel root directory doesn't contain 'index.php' file, but i added a
dummy 'index.php' file anyway because it was needed by Azure to
validate the build.
I removed the 'composer.json' file from the local git because i didn't
need to run composer install. i just wanted to copy app & routes
folder from the repo folder to 'wwwroot'

You never actually switch to the BASEDIR by doing e.g. cd $BASEDIR so your working directory never actually changes so here's one way around this:
echo "Refresh script"
echo "Script executed from: ${PWD}"
BASEDIR=$(dirname $0)
echo "Script location: ${BASEDIR}"
$(
cd $BASEDIR
php artisan cache:clear
)
Note the multiline $(...) is to execute the contents but preserve the original working directory when complete.
Alternatively you can do:
echo "Refresh script"
echo "Script executed from: ${PWD}"
BASEDIR=$(dirname $0)
echo "Script location: ${BASEDIR}"
php $BASEDIR/artisan cache:clear

I achieved what i was looking for using a different approach.
I used the Custom Deployment Script. (as per this link)
The Custom Deployment let you totally handle the deployment process yourself.
So i wrote a script to copy the files from the repo to the wwwroot.
But i faced another issue which is the php-cli that the kudu runs doesn't include any database modules as per this issue i found at the kudu's repo.
So, i came with a solution to run my artisan commands(which are mainly cache refreshing)
programtically using Laravel Controller. and curl HTTP Request to call this link to execute the
artisan commands using this controller.
Not the ideal solution. but it works
Here is my .deployment file
[config]
command = ./deploy.sh
and here is my deploy.sh
rm -rf $DEPLOYMENT_TARGET/app
rm -rf $DEPLOYMENT_TARGET/resources
rm -rf $DEPLOYMENT_TARGET/routes
rm -rf $DEPLOYMENT_TARGET/public/*.js
rm -rf $DEPLOYMENT_TARGET/public/*.svg
rm -rf $DEPLOYMENT_TARGET/public/*.eot
rm -rf $DEPLOYMENT_TARGET/public/*.css
rm -rf $DEPLOYMENT_TARGET/public/*.ico
rm -rf $DEPLOYMENT_TARGET/public/*.woff2
rm -rf $DEPLOYMENT_TARGET/public/*.woff
rm -rf $DEPLOYMENT_TARGET/public/*.ttf
\cp -RTf $DEPLOYMENT_SOURCE $DEPLOYMENT_TARGET
rm -rf $DEPLOYMENT_SOURCE/app
rm -rf $DEPLOYMENT_SOURCE/resources
rm -rf $DEPLOYMENT_SOURCE/routes
rm -rf $DEPLOYMENT_SOURCE/public
php /home/site/wwwroot/refresh-app.php
You can call the link to refresh the artisan commands inside refresh-app.php using curl or any other favorite way.

Related

Golang linter issues 'context loading failed: no go files to analyze'

We are using
golangci-lint version 1.40.1 together with
golang version 1.16.4
in our project for linting our Golang code.
Until now, what we did is running this bash script (from the root
directory of our repository):
if ! [ -x "$(command -v golangci-lint)" ]; then
echo "Fetching linter..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint
go mod tidy
fi
golangci-lint run --build-tags="unit contract container"
With some recent updates of Golang and golangci-lint, we suddenly face this error message:
ERRO Running error: context loading failed: no go files to analyze
There is a lengthy post on GitHub regarding this issue but the only useful suggestion there is to turn off the GO111MODULE env variable. When I run the linter with GO111MODULE turned off like
GO111MODULE=off golangci-lint run --build-tags="unit contract container"
the upper error message disappears but instead I am getting lots of false linting errors like:
api/router.go:152:5: undeclared name: `PermissionUpdatePackage` (typecheck)
PermissionUpdatePackage,
^
My go environment looks like this:
GO111MODULE=on
GOPATH=/Users/USER/workspace/go
GOROOT=/usr/local/opt/go/libexec
GOPRIVATE=*.CUSTOMER.com
GOSS_PATH=/usr/local/bin/goss
I tried to install the linter via go get... as well as go install ... and finally brew install golangci-lint which seems to be the recommended way following this documentation.
Running a go get ./... in the root of the project eventually solved the issues. In between we ran the following commands that probably cleared some (module?) caches that might have caused trouble as well:
golangci-lint cache clean && go clean -modcache -cache -i
golangci-lint run -v --timeout=5s
The error message
ERRO Running error: context loading failed: failed to load packages: timed out to load packages: context deadline exceeded
in the latter command pointed us to this GitHub post that made me try out go get ./...
For installing the linter (with a specified version), we ended up with this script:
linter_version='1.40.1'
if ! [ -x "$(command -v golangci-lint)" ]; then
echo "Fetching linter..."
# we cannot install linter in the project directory, otherwise we get dependency errors
# hence, temporarily jump into the /tmp directory
pushd /tmp > /dev/null
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint#v"${linter_version}" 2>&1
popd >/dev/null
fi

Not able to launch heroku cli on cygwin

As I don't have admin rights on my laptop, so downloaded the zip version of heroku CLI for deploying my app. When I execute the cmd from the bin path of the heroku it's launching and working fine, but when trying to launch from cygwin it's not working. Followed below workaround as I thought path issues, symlinks issues
.bash_profile
#Setting the heroku path on the cygwin
export PATH=$PATH:"/cygdrive/c/Django/heroku/bin/heroku"
export CYGWIN="winsymlinks:native"
cd C:/cygdrive && rm -rf c && ln -s -v C:/ c
.bashrc
alias heroku="/cygdrive/c/Django/heroku/bin/heroku"
which are suggested in the SO, but not helpful and I'm getting below error when trying to execute $ heroku in cygwin..
$ heroku
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module 'C:\cygdrive\c\Django\heroku\bin\run'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980
:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_ma
in.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Note: I'm able to launch heroku from GIT bash and CMD
whole time I was adding wrong files to the path and also executing them, Extracted zip folder of heroku contains following files
So, what I did..? copied the full path of bin including heroku.cmd file and pasted in the below file ".bashrc" as alias.
.bashrc
alias heroku="/cygdrive/c/Django/heroku/bin/heroku.cmd"
as heroku.cmd file is a script file and it contains set of commands for the heroku.
and I'm able to login to heroku and create app as well.

Download Fuchsia source -- Jiri hooks are not run due to fatal errors when updating projects or packages

Per Get Fuchsia source code:
~$ echo $PATH
/media/cwh/32GB/swdev/fuchsia/.jiri_root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
~$ cd /media/cwh/32GB/swdev/
/media/cwh/32GB/swdev$ curl -s "https://fuchsia.googlesource.com/fuchsia/+/master/scripts/bootstrap?format=TEXT" | base64 --decode | bash
cipd bootstrapped to path:"/media/cwh/32GB/swdev/fuchsia/.jiri_root/bin/cipd"
Please add /media/cwh/32GB/swdev/fuchsia/.jiri_root/bin to your PATH
[22:15:04.404] Updating all projects
PROGRESS: Fetching CIPD packages
[22:38:10.385] Jiri hooks are not run due to fatal errors when updating projects or packages
[23:01:03.457] Jiri hooks are not run due to fatal errors when updating projects or packages
ERROR: context deadline exceeded
I do not see any "fatal errors" preceding the Jiri hooks message.
What is the 'Jiri hooks are not run due to fatal errors when updating projects or packages'?
jiri help update indicates there are two default timeouts:
-fetch-packages-timeout=30
-hook-timeout=5
Invoke jiri directly with increased timeouts then repeat original command.
cd fuchsia; jiri update -fetch-packages-timeout=90 -hook-timeout=60; cd ..
curl -s "https://fuchsia.googlesource.com/fuchsia/+/master/scripts bootstrap?format=TEXT" | base64 --decode | bash
In my case it was the cipd that failed to fetch some prebuilt artifacts. Just login by running
cipd auth-login
and then run the fuchsia bootstrap script again.

Deploying PhantomJS 2.5 beta on Heroku. How can I see what's failing?

I'm trying to make a custom buildpack to deploy PhantomJS 2.5 beta version on Heroku. This is my buildpack based on Stomita's Phantomjs Buildpack which runs version 2.1.1 and works fine.
This is what I get in the building process:
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> PhantomJS app detected
remote: -----> Fetching PhantomJS 2.5.0-beta binaries at https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.5.0-beta-linux-ubuntu-trusty-x86_64.tar.gz
remote: ! Push rejected, failed to compile PhantomJS app.
remote:
remote: ! Push failed
remote: Verifying deploy....
remote:
remote: ! Push rejected to rp-phantom.
remote:
As you can see, not much information. The binary is downloaded fine, I checked that omitting the -s flag in the curl command, but can't figure out what's failing.
This is my compile file:
#!/bin/sh
set -e
BUILD_DIR=$1
CACHE_DIR=$2
# config
VERSION="2.5.0-beta"
# Buildpack URL
ARCHIVE_NAME=phantomjs-${VERSION}-linux-ubuntu-trusty-x86_64
FILE_NAME=${ARCHIVE_NAME}.tar.gz
BUILDPACK_PHANTOMJS_PACKAGE=https://bitbucket.org/ariya/phantomjs/downloads/${FILE_NAME}
mkdir -p $CACHE_DIR
if ! [ -e $CACHE_DIR/$FILE_NAME ]; then
echo "-----> Fetching PhantomJS ${VERSION} binaries at ${BUILDPACK_PHANTOMJS_PACKAGE}"
curl $BUILDPACK_PHANTOMJS_PACKAGE -L -s -O $CACHE_DIR/$FILE_NAME
fi
echo "-----> Extracting PhantomJS ${VERSION} binaries to ${BUILD_DIR}/vendor/phantomjs"
mkdir -p $CACHE_DIR/$ARCHIVE_NAME
mkdir -p $BUILD_DIR/vendor
tar -xvf $CACHE_DIR/$FILE_NAME -C $CACHE_DIR
mv $CACHE_DIR/$ARCHIVE_NAME $BUILD_DIR/vendor/phantomjs
echo "-----> exporting PATH and LIBRARY_PATH"
PROFILE_PATH="$BUILD_DIR/.profile.d/phantomjs.sh"
mkdir -p $(dirname $PROFILE_PATH)
echo 'export PATH="$PATH:$HOME/vendor/phantomjs/bin"' >> $PROFILE_PATH
echo 'export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:vendor/phantomjs/lib"' >> $PROFILE_PATH
Thanks in advance!
I was able to get 2.5.0 beta working on Heroku. Here is my answer from my own post:
Ultimately, I was able to figure it out! There are a few things that you have to do...
Dependencies: You have to use the Heroku Apt buildpack to install the missing dependencies. First, you need to add the buildpack to your app:
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt
Next, you'll create a file in your project root called Aptfile. Here's where we add the missing dependencies for PhantomJS 2.5.0 Beta. 2.5.0 introduces webp support, so we need that. libhyphen0 is required as well, though I'm not sure how it us used. Finally, we use gcc-5 and the latest libstdc++6. Contents should look like this:
webp
libhyphen0
https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/gcc-5_5.4.1-8ubuntu1_amd64.deb
https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.4_amd64.deb
PhantomJS: Next we grab the latest version of PhantomJS. I've created a fork of the most popular PhantomJS buildpack and updated it for use with 2.5.0 beta. 2.5.0 beta has builds for trusty as well as xenial, so the build pack will detect the Heroku stack and use the appropriate one (though the cedar-16 stack is still in beta at the time of this post). So, add it to your app:
heroku buildpacks:add https://github.com/lookitsatravis/heroku-buildpack-phantomjs.git
Deploy: All that's left is deployment! Commit the Aptfile to your repo, make sure the build packs are setup, and then push to Heroku.
Took a bit of trial and error, but ultimately I was able to get it up and running. Hope this helps others until the final candidate is released.

Composer installs only globally (Windows 10)

When I try to install Composer (exe installer, curl, tried all methods), it installs only in C:\ProgramData\ComposerSetup\bin and never localy, even if I run it (obviously) from another directory.
When I run composer init - it does not create json config anywhere, composer install - is installing only in C:/Users/Username/AppData/Roaming/Composer/
D:\test>composer init
←[37;44m ←[39;49m
←[37;44m Welcome to the Composer config generator ←[39;49m
←[37;44m ←[39;49m
This command will guide you through creating your composer.json config.
Package name (<vendor>/<name>) [←[33mUsername/test←[39m]: test/test
Description []:
Author []: test <test#test.test>
Minimum Stability []:
Package Type []:
License []:
Define your dependencies.
Would you like to define your dependencies (require) interactively [←[33myes←[39m]?
Search for a package:
Would you like to define your dev dependencies (require-dev) interactively [←[33myes←[39m]?
Search for a package:
{
"name": "test/test",
"authors": [
{
"name": "test",
"email": "test#test.test"
}
],
"require": {}
}
D:\test>dir
29.08.2015 12:39 <DIR> .
29.08.2015 12:39 <DIR> ..
0 files
D:\test>composer require slim/slim -vvv
Reading ./composer.json
Loading config file ./composer.json
Executing command (CWD): git describe --exact-match --tags
Executing command (CWD): git branch --no-color --no-abbrev -v
Executing command (CWD): hg branch
Executing command (CWD): svn info --xml
Reading C:/Users/Username/AppData/Roaming/Composer/composer.json
Loading config file C:/Users/Username/AppData/Roaming/Composer/composer.json
Executing command (CWD): git describe --exact-match --tags
Executing command (CWD): git branch --no-color --no-abbrev -v
Executing command (CWD): hg branch
Executing command (CWD): svn info --xml
Downloading https://packagist.org/packages.json
Writing C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/packages.json into cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2013.json from cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2014.json from cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2014-10.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-01.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-04.json from cache Downloading http://packagist.org/p/provider-2015-07$bf4d7ab35da85686431ee3c47d0d6d2eee3d913013b38506fbc197c5e95c2420.json
Writing C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-07.json into cache Downloading http://packagist.org/p/provider-latest$ee6937b535cc76629a8e81c4362790bd14ce6a824def5d75f7222438e756a7b0.json
Writing C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-latest.json into cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/provider-slim$slim.json from cache Using version ←[32m^2.6←[39m for ←[32mslim/slim←[39m
←[32m./composer.json has been updated←[39m
Reading ./composer.json
Loading config file ./composer.json
Executing command (CWD): git describe --exact-match --tags
Executing command (CWD): git branch --no-color --no-abbrev -v
Executing command (CWD): hg branch
Executing command (CWD): svn info --xml
Reading C:/Users/Username/AppData/Roaming/Composer/composer.json
Loading config file C:/Users/Username/AppData/Roaming/Composer/composer.json
Executing command (CWD): git describe --exact-match --tags
Executing command (CWD): git branch --no-color --no-abbrev -v
Executing command (CWD): hg branch
Executing command (CWD): svn info --xml
←[32mLoading composer repositories with package information←[39m
Downloading https://packagist.org/packages.json
Writing C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/packages.json into cache
←[32mUpdating dependencies (including require-dev)←[39m
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2013.json from cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2014.json from cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2014-10.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-01.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-04.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-07.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-latest.json from cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/provider-slim$slim.json from cache Analyzed 63 packages to resolve dependencies
Analyzed 45 rules to resolve dependencies
- Installing ←[32mslim/slim←[39m (←[33m2.6.2←[39m)
Reading C:/Users/Username/AppData/Local/Composer/files/slim/slim/20a02782f76830b67ae56a5c08eb1f563c351a37.zip from cache
Loading from cache
Extracting archive
REASON: Required by root: Install command rule (install slim/slim 2.6.0|install slim/slim 2.6.1|install slim/slim 2.6.2)
←[32mWriting lock file←[39m
←[32mGenerating autoload files←[39m
Any ideas how to fix it?
Before applying all steps, try step 5 with your current setup.
Installation Steps
Manually download: https://getcomposer.org/composer.phar
place composer.phar into your PHP folder, next to php.exe
add a batch file composer.bat in the same folder (to execute composer a bit easier), with the following content:
#echo off
:: Composer CLI Shortcut (Global Installation)
"%~dp0php.exe" "%~dp0composer.phar" %*
pause
add the PHP folder to your ENV path, so that php and composer are available on any path
then create your new project
mkdir slim
cd slim
composer require slim/slim 2.6.2 -vvv (this time with version)

Resources