how to run a github runner as root - github-actions

I am trying to run my github runner as root for self hosted linux servers. Can anyone point me to easy solution that I can implement quickly in following code:
name: Test
on: push
jobs:
Test1:
runs-on: selfhosted-linux # This should run on this self hosted runner only
steps:
- uses: actions/checkout#v2
At this point I cannot ssh into the selfhoste linux but can access it only via code in the workflow folder
and I would like to run the checkout as root rather then non root user.

You need to set the environment variable RUNNER_ALLOW_RUNASROOT before you run config.sh to set up the runner. e.g.
RUNNER_ALLOW_RUNASROOT=1 ./config.sh --token asdlkjfasdlkj

Related

How to send artifacts from github actions to azure windows VM

I have build my project with GitHub actions pipeline running on windows agent. The artifacts are generated and stored in the repo. The next task of mine is to send it to the azure windows VM. I really don't know how to do this. Anyone can please help me.
name: Deploy to Azure Windows VM
on:
push:
branches:
- do/cs
jobs:
deploy:
runs-on: windows-2019
steps:
- name: Checkout code
uses: actions/checkout#v3
And continue this pipeline to build my C# project. Now the artifacts are downloaded in the repo, I am wishing to send it to AZURE windows VM. Here is the action I am using:
- name: Copy artifacts to azure VM
uses: azure/scp-action#v2
with:
host: 'VM-public-ip'
username: 'azureuser'
password: 'pwsd'
source: ./test.zip
target: 'C:\\Users\a\zureuser\\'
Where test.zip are the artifacts downloaded into the repo.
Kindly continue this pipeline and deploy my artifacts to windows VM. Assume that we have artifacts by the name of test.zip. I have build my project but cannot make it happen to deploy to azure windows VM.
Kindly help me. Thanks
Anyone please help:)

Run commands on the runner directly even if a container is used for GitHub Actions

Is there a way to use the run directly on the runner? I use a container like this:
jobs:
test:
runs-on: ubuntu-latest
container: debian:10-slim
steps:
- name: Runs on container
run: |
ls -l
If i would want to use the ghcommand, which is installed on the runner (ubuntu-latest) by default, is there a way to use run in this context? Or do i loose all access to the runner if i choose a container?

Docker cache not working on repository dispatch

I have a workflow that builds a Docker image.
When the workflow runs with manual trigger/push trigger the cache works fine and I get really good performance.
When I trigger the workflow through repository dispatch (another workflow that triggers the workflow) the cache doesn't work.
I tried everything: using cache module with all storage possibilities there are, running on GitHub runner, running on self-hosted runner, using bash commands to build and push the image instead of using a module, nothing seems to work.
Did anyone come across a similar issue?
This is how build and push look at the moment (on a self hosted runner):
- name: Build Docker image
id: image_id
run: |
docker build -f Dockerfile.test --build-arg LAMBDA_NAME=sharon-test LAMBDA_HANDLER=dist/apps/test/main.handler --build-arg NPM_TOKEN=${{ secrets.NPM_TOKEN }} -t ****.dkr.ecr.us-east-2.amazonaws.com/sharon-test:latest .
- name: Push Docker image
run: |
docker push ****.dkr.ecr.us-east-2.amazonaws.com/sharon-test:latest

Unable to resolve jar dependency in Java project for

I have 2 java projects on GitHub, the first project produces a java library and the second project uses it.
The first project is build via first job in yaml file and it installs the library in /home/runner/.m2/repository/ successfully
Then when the second project is build via the second job in the same yaml file , it fails with error
Failed to execute goal on project <>: Could not resolve dependencies
for project Could not find artifact <>:jar:1.0-
SNAPSHOT -> [Help 1]
In my second project, I have included the dependency to load this library jar(produced by first project) from the repository.
MY understanding is that my second project should load the jar library from the /home/runner/.m2/repository/ but its not loading it.
Any help is appreciated.
Also can we access /home/runner/.m2/repository/ to check if it contains the library jar.
./project_account_library/account_library => Contains maven project
./project_account_service/account_service => Contains maven project
./.github/workflows/build.yml
Here is the yml file
name: Build account service
on:
push:
branches: [main]
env:
IMAGE_NAME: accountservice
jobs:
build_dependency:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout#v2
- uses: actions/setup-java#v2
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
- name: Build Dependency
run: |
cd ./project_account_library/account_library
mvn clean install
build_accountservice:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout#v2
- uses: actions/setup-java#v2
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
- name: Build Account Service
run: |
cd ./project_account_service/account_service
mvn clean install
First Step
[INFO] Installing /home/runner/work/<>/<>/target/account_
library_1.0-SNAPSHOT.jar to
/home/runner/.m2/repository/com/<>/<>/account_library/1.0-
SNAPSHOT/account_library-1.0-SNAPSHOT.jar
Second Step
Error: Failed to execute goal on project <>: Could not resolve
dependencies for project <>: Could not find artifact com.<>.
<>:account_library:jar:1.0-SNAPSHOT -> [Help 1]
Thanks Frennky
I now used only 1 job and below is my new .yml file
- name: Build Account Service
run: |
cd ./project_account_library/account_library
mvn clean install
cd ../../project_account_service/account_service
mvn clean install
First directory is successfully built but it fails to cd to ../../project_account_service/account_service and fails to build with below error
/home/runner/work/_temp/ea229141-b0c3-455d-82f0-12ff588d420a.sh: line 12: cd ../../project_account_service/account_service: No such file or directory
The reason you're missing dependencies on your second job is because those 2 jobs, by default, run in parallel and they do so on 2 different runners. From docs:
Each job will run inside its own virtual machine runner, or inside a
container...
There's few ways you can go around this. I can suggest one quick and easy, and another that would probably be a way to go, but require slightly more effort.
Easy way out of this is to put all steps in a single job.
Better way would be to make use of Github Package repository, where
you could push your lib/dependencies and then resolve them for your
service.
For more details on Github Package repository you can check docs.
Update:
Ok, I've reread your new error and I think I understand the issue.
If I got it right your dir structure is as follows:
repo
project_account_library
account_library
project_account_service
account_service
Each run step actually starts at root of you repo. You can use working-directory like so:
# ...
- name: Build Dependency
run: mvn clean install
working-directory: ./project_account_library/account_library
# ...
- name: Build Account Service
run: mvn clean install
working-directory: ./project_account_service/account_service

composite run steps action not working under alpine

I followed the steps documented here https://docs.github.com/en/free-pro-team#latest/actions/creating-actions/creating-a-composite-run-steps-action and created a custom github action sucessfully.
Problem now: it only works if the bash shell is available. Unfortunately the shell property is required and it is not possible to use an input variable for that (tested both).
This, doesn't work:
jobs:
build:
runs-on: ubuntu-latest
name: Build project
container: elixir:1.10.4-alpine
env:
MIX_ENV: prod
steps:
- uses: actions/checkout#v2
- name: My custom composite action
uses: path/to-my-custom-composite-action#version
Error: OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "bash": executable file not found in $PATH: unknown
Now I can duplicate the action for alpine (using sh) or build a second version especially for alpine (perhaps autom. via build environment). Is there a better solution?