Docker based runner to use private image to build - github

My self-hosted docker based runner already activated at GitHub organization level. Separately to perform npm build through our private docker image, Trying with below workflow yml code.
name: CI with Docker
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: docker-runner # This is our Self-hosted docker runner
container:
image: ubuntu:npm-1 # This is our private docker image.
steps:
- uses: actions/checkout#v2
- name: Build
run: npm install
It fails with Error: docker: command not found this is expected since my docker-runner image doesn't loaded with docker engine package.
With Self-hosted docker runner, How do i call a private docker image and perform the build? Some pointers to achieve would be helpful. Thanks!

Related

Github Actions - Invalid workflow file

I am trying to build CI/CD pipelines using GitHub Actions but unfortunately, I am stuck with an error with the yaml file.
Here is my Yaml file is:
---
name: Build and push python code to gcp with github actions
on:
push:
branches:
- main
jobs:
build_push_grc:
name: Build and push to gcr
runs_on: unbuntu-latest
env:
IMAGE_NAME: learning_cicd
PROJECT_ID: personal-370316
steps:
- name: Checkoutstep
uses: actions/checkout#v2
- uses: google-github-actions/setup-gcloud#master
with:
service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY}}
project_id: ${{ env.PROJECT_ID }}
export_default_credentials: true
- name: Build Docker Image
run: docker build -t $IMAGE_NAME:latest .
- name: Configure Docker Client
run: |-
gcloud auth configure-docker --quiet
- name: Push Docker Image to Container Registry (GCR)
env:
GIT_TAG: v0.1.0
run: |-
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:$GIT_TAG
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:$GIT_TAG
Here is an error where I am stuck with:
GitHub Actions
/ .github/workflows/gcp.yaml
Invalid workflow file
You have an error in your yaml syntax on line 15
I tried all possible indentations available on the internet but had no luck. I tried Yamllinter but still could not find where the error comes from. Please point me to where I am going wrong.
Thanks.
The runs-on (not runs_on) should have two spaces indentation relative to the job identifier. Also, the OS should be ubuntu-latest.
Then, env should have the same indentation as runs-on or name, the same as steps.
Here is the correct WF:
---
name: Build and push python code to gcp with github actions
on:
push:
branches:
- main
jobs:
build_push_grc:
name: Build and push to gcr
runs-on: ubuntu-latest
env:
IMAGE_NAME: learning_cicd
PROJECT_ID: personal-370316
steps:
- name: Checkoutstep
uses: actions/checkout#v2
- uses: google-github-actions/setup-gcloud#master
with:
service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY}}
project_id: ${{ env.PROJECT_ID }}
export_default_credentials: true
- name: Build Docker Image
run: docker build -t $IMAGE_NAME:latest .
- name: Configure Docker Client
run: |-
gcloud auth configure-docker --quiet
- name: Push Docker Image to Container Registry (GCR)
env:
GIT_TAG: v0.1.0
run: |-
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:$GIT_TAG
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:$GIT_TAG
I would recommend debugging such issues in the GitHub file edit form (editing the yml file in the .github/workflows directory). It will highlight all the issues regarding the workflow syntax. Demo.

why I can run docker-compose in Github action without install it

I make a copy/paste from the link here. I am confused about why I can run docker-compose without installing it. When I test locally using "act", it will give me an error about docker-compose command not found.
name: CI-dev-pipeline
on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]
jobs:
build:
runs-on: ubuntu-latest
container:
image: lucasalt/act_base:latest
steps:
- uses: actions/checkout#v2
with:
path: "<INSERT_NAME_OF_REPOSITORY>"
- name: Build docker
run: |
docker-compose -f ./<REPO_NAME>/docker-compose.test.yml -p testing up -d
You are using a docker-image from "lucasalt/act_base".
If you look at the description of the images it states:
act_base is a custom runner for the act project. This image contain Node, npm, yarn, docker and docker-compose.
Meaning that it already downloads docker-compose etc. for you.

GitHub Actions - Have Checkout action in its own job

I'm trying to configure a workflow in GitHub Actions using a self-hosted runner.
The runner itself has Node installed for the checkout task, but not Python, hence why I'm trying to run the python script inside the specified container. I'm trying to execute a simple Python script from inside the repo, however, when the second job runs inside the container, it cannot find the file main.py.
name: GitHub Actions Test
on:
workflow_dispatch:
inputs:
job:
description: 'checkout and run'
required: true
default: 'checkout-repo'
jobs:
checkout-repo:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout#v3
run-python:
runs-on: self-hosted
container:
image: <some_python3_docker_image>
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
steps:
- run: python3 main.py
Is there any way to make the repo workspace persist between the two jobs?

gh-pages deployment issue, job fails on deploy. The directory you're trying to deploy ... doesn't exist

gh-pages deployment fails with next error: My repository failed job
Checking configuration and starting deployment… 🚦
Error: The directory you're trying to deploy named /home/runner/work/azure-flask-react/azure-flask-react/dist doesn't exist. Please double check the path and any prerequisite build scripts and try again. ❗
Deployment failed! ❌
I'm trying to deploy ReactApp at Github and besides deploy Python-Flask backend hosted at Azure and back-app has its automatically generated job yml.
But for front-app I followed this answer and manually added second job in yml because I need to provide env.variables.
My backend deployment succeeds but front-app constantly fails because of duplicated path
/home/runner/work/azure-flask-react/azure-flask-react/dist
Here is my yml and package.json but there is no any extra mentioning of that directory...
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Python app to Azure Web App - first-py-app
on:
push:
branches:
- main
workflow_dispatch:
jobs:
front-build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v1
- name: Build
run: |
npm --prefix front-app install
npm --prefix front-app run-script build
env:
REACT_DEV_SERVER_URL: ${{ secrets.REACT_DEV_SERVER_URL }},
REACT_DEV_FRONT_APP_URL: ${{ secrets.REACT_DEV_FRONT_APP_URL }}
- name: Deploy
uses: JamesIves/github-pages-deploy-action#releases/v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN_KEY }}
BRANCH: gh-pages
FOLDER: dist
back-build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#master
- name: Set up Python version
uses: actions/setup-python#v1
with:
python-version: '3.8'
- name: Build using AppService-Build
uses: azure/appservice-build#v2
with:
platform: python
platform-version: '3.8'
- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy#v2
with:
app-name: 'first-py-app'
slot-name: 'production'
publish-profile: ${{ secrets.AzureAppService_PublishProfile_7edcdecca83a4354a87943f94bb32fca }}
{
...
"homepage": "https://nikonov91-dev.github.io/azure-flask-react",
"scripts": {
...
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
}
and my file structure
azure-proj
|-front-app (containing reactjs)
|-package.json
|-node_modules
|-src
|-app.py (python-flask application which deploys successfully)
I misunderstood the issue message, the problem was not duplicating the problem was the missed inner path passed in FOLDER in gh-pages YML settings
There was a hint in BUILD step
And one more thing: do not forget to get and add to GH your personal-access-token

How to run a script inside a private docker image

We are currently using CircleCI to run our automated tests and would like to migrate to Azure DevOps to run those tests on an Azure Pipeline. Our applications are fully dockerized and I am having trouble executing the tests in the container on Azure Pipeline.
My goal is simply to build the image, push it to our Docker Hub repo and then pull it to execute PHPUnit. The first part is OK, I managed to push the image.
Then I created a job to execute a simple script, and I would like for it to run inside the container. My pipeline conf file will follow. The step that fails currently is the container initialization of the second job. It fails with the error :
/usr/bin/docker pull [redacted]:azure-master
Error response from daemon: pull access denied for [redacted], repository does not exist or may require 'docker login': denied: requested access to the resource is denied
trigger:
- master
resources:
- repo: self
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build_and_push
displayName: Build and push image
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Docker#2
displayName: Build and push image
inputs:
containerRegistry: 'Docker Hub'
repository: '[redacted]'
command: 'buildAndPush'
Dockerfile: '**/Dockerfile'
tags: 'azure-$(Build.SourceBranchName)'
- task: Docker#2
displayName: Login to docker repo
inputs:
containerRegistry: 'Docker Hub'
command: 'login'
- job: Install_composer_and_run_tests
dependsOn: ['Build_and_push']
pool:
vmImage: 'ubuntu-latest'
container: [redacted]:azure-$(Build.SourceBranchName)
steps:
- task: Docker#2
displayName: Login to docker repo
inputs:
containerRegistry: 'Docker Hub'
command: 'login'
- script: composer install -n --prefer-dist
- script: php vendor/bin/phpunit tests/ --group me
I don't really understand how or where I should login because I use the container param in the job, not a task to pull the image. Plus I have not problem pushing the image even though I did not explicitly login at that step. Last thing is that I have created a container registry in Azure DevOps (Docker Hub), with my credentials and it works correctly.
Thanks for your help :)
See Endpoints:
Containers can be hosted on registries other than Docker Hub. To host an image on Azure Container Registry or another private container registry, add a service connection to the private registry. Then you can reference it in a container spec:
container:
image: xxx/xxx:tag
endpoint: xxx
According to your error message, you may need to provide credentials for the Initialize Containers step. So we should use this format:
- job: Install_composer_and_run_tests
dependsOn: ['Build_and_push']
pool:
vmImage: 'ubuntu-latest'
container:
image: [redacted]:azure-$(Build.SourceBranchName)
endpoint: 'Docker Hub'
steps:
...