Command not found when SSHing into server via non-interactive session - github-actions

I'm using a GitHub action to SSH into my staging server to pull the latest from the repo (which succeeds) then install node modules: yarn (which fails), build the app: yarn build:app (which fails), then restart the app: pm2 restart all (which fails). From what I've read from researching, the commands aren't found because the SSH into the server is a non-interactive session and many things aren't added to $PATH. I have tried adding export PATH="$PATH:/home/***/.nvm/versions/node/v14.5.0/bin/pm2:/home/***/.nvm/versions/node/v14.5.0/bin/pm2" to my script to no avail. I'm still getting command not found.
name: Test Deployment
on:
push:
branches:
- staging
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy Staging
if: github.ref == 'refs/heads/staging'
uses: appleboy/ssh-action#master
with:
host: ${{ secrets.STAGING_SSH_HOST }}
username: ${{ secrets.STAGING_SSH_USERNAME }}
key: ${{ secrets.STAGING_SSH_KEY }}
passphrase: ${{ secrets.STAGING_SSH_PASSPHRASE }}
port: ${{ secrets.STAGING_SSH_PORT }}
script: |
export PATH="$PATH:/home/***/.nvm/versions/node/v14.5.0/bin/pm2:/home/***/.nvm/versions/node/v14.5.0/bin/pm2"
cd ~/***
git pull origin staging
yarn
yarn build:app
pm2 restart all
Receiving errors:
======CMD======
export PATH="$PATH:/home/***/.nvm/versions/node/v14.5.0/bin/pm2:/home/***/.nvm/versions/node/v14.5.0/bin/pm2"
cd ~/***
git pull origin staging
yarn
yarn build:app
pm2 restart all
======END======
err: From github.com:***/***
err: * branch staging -> FETCH_HEAD
err: *** staging -> origin/staging
out: Merge made by the 'recursive' strategy.
2021/04/16 21:28:17 Process exited with status 127
out: .github/workflows/main.yml | 2 +-
out: 1 file changed, 1 insertion(+), 1 deletion(-)
err: bash: line 3: yarn: command not found
err: bash: line 4: yarn: command not found
err: bash: line 5: pm2: command not found

Instead of
export path='$PATH:/home/***/.nvm/versions/node/v14.5.0/bin/pm2:/home/***/.nvm/versions/node/v14.5.0/bin/pm2'
you should try
export PATH="$PATH:/home/***/.nvm/versions/node/v14.5.0/bin/pm2:/home/***/.nvm/versions/node/v14.5.0/bin/pm2"
Notice:
PATH - uppercase
Use double quote instead of single quote to expand the previous value of PATH variable

Related

What is skaffold doing after skaffold build pushed successfully

When I run skaffold in a github workflow like this
skaffold build
it calls the gradle jib correctly, creates an image and pushes it to the ghcr successfully. Grdale finishes successfully as can be seen in the log. Nevertheless, something happens afterwards that fails. It seems someone tries to access the just built image but is not authorized. This does not happen, if I execute it locally. And it does not fail in the github workflow if I call gradlew jib directly without skaffold being involved.
Built and pushed image as ghcr.io/tobias-neubert/motd-service:453f4c4-dirty
BUILD SUCCESSFUL in 11s
4 actionable tasks: 4 executed
time="2023-02-15T12:07:09Z" level=error msg="No matching credentials were found for \"ghcr.io\""
time="2023-02-15T12:07:09Z" level=error msg="No matching credentials were found for \"ghcr.io\""
getting image: GET https://ghcr.io/token?scope=repository%3Atobias-neubert%2Fmotd-service%3Apull&service=ghcr.io: UNAUTHORIZED: authentication required
Error: Process completed with exit code 1.
The github workflow:
name: Build and push motd-service
on:
push:
permissions:
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout#v3
- name: Set up Java
uses: actions/setup-java#v2
with:
java-version: 17
distribution: temurin
- name: Setup Gradle
uses: gradle/gradle-build-action#v2
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Install skaffold
run: |
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && \
sudo install skaffold /usr/local/bin/
- name: Deactivate collecting skaffold metrics
run: skaffold config set --global collect-metrics false
- name: Build the motd image
env:
GH_PASSWORD: '${{ secrets.GITHUB_TOKEN }}'
run: skaffold build
Does anybody know what happens here?
It tries to fetch the digest of the new image, which it needs to render the k8s resources. Pushing the image was made by gradle. The jib plugin is configured to use environment variables for authenticating against ghcr.io. But skaffold does not know about those. So it fails to authenticate. A docker login does the trick, although it is not safe in a CI. So now I have to search for a better way to tell skaffold to authenticate against the registry

GitHubActions Runner Error: Command failed: go env GOPATH

We have GitHubActions and we run it in an Centos Server. We have set the root's .bashrc as export GOROOT=/opt/go export PATH=$PATH:$GOROOT/bin
In the Github Actions we have the file:
setup:
needs: cleanup
name: Setup
runs-on: [self-hosted, Linux, X64, CentOS-Linux-7.9]
services:
postgres:
image: postgres:latest
- name: Set up Go 1.17
uses: actions/setup-go#v2
with:
go-version: 1.17
# id: Go
- run: go version
- name: Checkout code into go module directory
uses: actions/checkout#v2
When Github Actions runs this , it throws the error:
0s
Run actions/setup-go#v2
with:
go-version: 1.17
stable: true
token: ***
...
Setup go stable version spec 1.17
Found in cache # /opt/actions-runner/_work/_tool/go/1.17.11/x64
Added go to the path
missing $GOPATH
Error: Command failed: go env GOPATH
missing $GOPATH
Can someone please help with this error?
The Go installation is working and on the Linux box as root 'go version' works.
That looks like actions/setup-go issue 116 which includes:
I believe the reason of issue is missing $HOME variable on the self-hosted runners.
The missing HOME variable makes it so that Go is not able to make default folders for GOPATH and GOCACHE and such.
So double-check what echo $HOME displays in your runner.
The OP AwsGeek confirms in the comments:
First as suggested I did an echo $HOME and it was empty and under the env: I added the value for home env: HOME: "/home/xxxx-account"

Github Actions Error: No such file or directory

Trying to troubleshoot my terraform init step, but I'm getting Error: No such file or directory
Even if I add the pwd as step 2 shown below, still getting Error: No such file or directory. This is working in other pipelines, but none of the new pipelines are working with the same commands.
Was there an update to GHA? I know they updated Helm, but did something else change that would adjust the behavior?
update-terraform-env:
name: "Create or Update Terraform Environment"
needs: build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.TERRAFORM_WORKING_DIR }}
steps:
- name: Checkout Source
uses: actions/checkout#v2
- name: Get directory
run: pwd
- name: Setup Terraform
uses: hashicorp/setup-terraform#v1.2.1
with:
terraform_version: 0.13.0
- name: Terraform Init
id: tf-init
run: terraform init
The env.TERRAFORM_WORKING_DIR was initialized to a path that didn't exist. (development which didn't exist, instead of develop which did).
The error of Error: No such file or directory was misleading as it seemed that the step command is failing, when it's actually the working directory for the entire job.

Using deployer with github actions to deploy private repository

I'm trying to deploy a PHP Project using github action
The connection on the target server works but I'm stuck at the part when deployer tries to clone the repository.
I'm storing a private ssh key in the github secret in order to access the server and I try to use the same ssh key to access the github repository (the key is added in the deploy key of the repository).
Here the command that fails :
cd {releasePath} && (/usr/bin/git clone -b "develop" --recursive git#github.com:arnaudschaeffer/myprivaterepo.git {releasePath} /releases/3 2>&1)
Command failed with exit code 1: bin/dep deploy staging -vvv
Deployer works from my local environment. I can make it work with both my personnal SSH Keys and the one I've had in a secret in order to connect to the target server.
Here's my github yml file :
# This is a basic workflow to help you get started with Actions
name: Deploy develop
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ develop ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
deploy:
name: Deploy to develop
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
with:
ref: 'develop'
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
persist-credentials: true
- name: Setup PHP
uses: shivammathur/setup-php#v2
with:
php-version: 7.4
- name: Configure SSH
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PORT: ${{ secrets.SSH_PORT }}
run: |
mkdir -p ~/.ssh/
echo "$SSH_PRIVATE_KEY" > ~/.ssh/staging.key
chmod 600 ~/.ssh/staging.key
cat >>~/.ssh/config <<END
Host github
Hostname github.com
IdentityFile ~/.ssh/staging.key
IdentitiesOnly yes
Host host_name
HostName $SSH_HOST
User $SSH_USER
Port $SSH_PORT
IdentityFile ~/.ssh/staging.key
StrictHostKeyChecking no
END
- name: Set Up Deployer
run: |
curl -LO https://deployer.org/deployer.phar && mkdir bin && mv deployer.phar bin/dep && sudo chmod +x bin/dep
# Add deploy key in GitHub account
- name: Deploy
uses: deployphp/action#master
with:
private-key: ${{ secrets.SSH_PRIVATE_KEY }}
#Both target server and github known hosts
known-hosts: ${{ secrets.KNOWN_HOSTS }}
dep: deploy staging -vvv
Is there some extra step to clone the repository in deployer ?
Thank in advance !

SFDX & Github Action - Warning: force:auth:sfdxurl:store is not a sfdx command

I have the following yaml file. It were working just fine until yesterday. Unfortunately starting from today received the below warning and followed by the following error.
Hope someone will be able to point me to solution to fixed this issue. Below is the yaml code
name: CI_dev
on:
pull_request:
branches: [ dev ]
jobs:
test_pipeline:
runs-on: ubuntu-latest
steps:
# Install Salesforce CLI
- name: Install Salesforce CLI
run: |
wget https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd64.tar.xz
mkdir sfdx-cli
tar xJf sfdx-linux-amd64.tar.xz -C sfdx-cli --strip-components 1
./sfdx-cli/install
#Checkout master
- name: 'checkout master'
uses: actions/checkout#master
#read secret, authenticate and deploy
- name: 'Populate auth file with SFDX_URL secret'
shell: bash
run: 'echo ${{ secrets.secret}} > ./secret.txt'
- name: 'Authenticate'
run: 'sfdx force:auth:sfdxurl:store --sfdxurlfile=./secret.txt -a secretAlias'
- name: 'Deploy'
run: "sfdx force:source:deploy --sourcepath ./force-app/main/default -l RunLocalTests -u secretAlias"
Below is the warning that appear on the authenticate step
Warning: force:auth:sfdxurl:store is not a sfdx command.
Did you mean auth:sfdxurl:store? [y/n]:
And below is the error that appear on the Deploy step
ERROR running force:source:deploy: No org configuration found for name secretAlias
Error: Process completed with exit code 1.
sfdx (at least linux distributions) have recently updated from 7.82.1 to 7.83.1 (January 2021)
since 7.83.1 it follows different syntax format.
You need to remove force: from your 'Authenticate' command line as it is advised in error message.
You can look your current version with:
sfdx --version
Busy Box was right. just need to remove force from force:auth and its alread working again. below is the updated yaml file as reference.
name: CI_dev
on:
pull_request:
branches: [ dev ]
jobs:
test_pipeline:
runs-on: ubuntu-latest
steps:
# Install Salesforce CLI
- name: Install Salesforce CLI
run: |
wget https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd64.tar.xz
mkdir sfdx-cli
tar xJf sfdx-linux-amd64.tar.xz -C sfdx-cli --strip-components 1
./sfdx-cli/install
#Checkout master
- name: 'checkout master'
uses: actions/checkout#master
#read secret, authenticate and deploy
- name: 'Populate auth file with SFDX_URL secret'
shell: bash
run: 'echo ${{ secrets.secret}} > ./secret.txt'
- name: 'Authenticate'
run: 'sfdx auth:sfdxurl:store --sfdxurlfile=./secret.txt -a secretAlias'
- name: 'Deploy'
run: "sfdx force:source:deploy --sourcepath ./force-app/main/default -l RunLocalTests -u secretAlias"