Terraform Kubernetes provider fails on Github Action with following: 'config_path' refers to an invalid path: "/github/home/.kube/config" - github

I am trying to create a CI build in Github Actions for Kubernetes deployment with Terraform on Minikube. The Terraform apply fails on deploying provider with following message:
Invalid attribute in provider configuration
with provider["registry.terraform.io/hashicorp/kubernetes"],
on providers.tf line 18, in provider "kubernetes":
18: provider "kubernetes" {
'config_path' refers to an invalid path: "/github/home/.kube/config": stat
/github/home/.kube/config: no such file or directory
How can I resolve it? I have tried various approaches but so far nothing works. Everything works fine when I deploy it locally with Minikube.
Relevant code snippets from Terraform:
variables.tf:
variable "kube_config" {
type = string
default = "~/.kube/config"
}
providers.tf:
provider "kubernetes" {
config_path = pathexpand(var.kube_config)
config_context = "minikube"
}
Github Actions job:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: setup minikube
uses: manusa/actions-setup-minikube#v2.7.2
with:
minikube version: 'v1.28.0'
kubernetes version: 'v1.25.4'
github token: ${{ secrets.GITHUB_TOKEN }}
driver: docker
container runtime: docker
- name: terraform-apply
uses: dflook/terraform-apply#v1.29.1
with:
path: terraform-k8s
auto_approve: true
I have also tried running it with official setup-minikube action, but doesn't work as well.

Seems like I have managed to make it work by using official Hashicorp's action instead of the original. Gonna check if it deploys everything in the end :)
- uses: hashicorp/setup-terraform#v2
- name: terraform-init
run: terraform -chdir=terraform-k8s init
- name: terraform-apply
run: terraform -chdir=terraform-k8s apply -auto-approve

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.

Github Actions "unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials"

I have created a github workflow to deploy to GCP. But when it comes to push the docker image to GCP I get this error
...
346fddbbb0ff: Waiting
a6fc7a8843ca: Waiting
unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication
Error: Process completed with exit code 1.
Here is my yaml file :
name: Build for Dev
on:
workflow_dispatch:
env:
GKE_PROJECT: bi-dev
IMAGE: gcr.io/bi-dev/bot-dev
DOCKER_IMAGE_TAG: JAVA-${{ github.sha }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
ref: ${{ github.event.inputs.commit_sha }}
- name: Build Docker Image
run: docker build -t ${{env.IMAGE}} .
- uses: google-github-actions/setup-gcloud#v0.2.0
with:
project_id: ${{ env.GKE_PROJECT }}
service_account_key: ${{ secrets.GKE_KEY }}
export_default_credentials: true
- name: Push Docker Image to GCP
run: |
gcloud auth configure-docker
docker tag ${{env.IMAGE}} ${{env.IMAGE}}:${{env.DOCKER_IMAGE_TAG}}
docker push ${{env.IMAGE}}:${{env.DOCKER_IMAGE_TAG}}
- name: Update Deployment in GKE
env:
GKE_CLUSTER: bots-dev-test
GKE_DEPLOYMENT: bot-dev
GKE_CONTAINER: bot-dev
run: |
gcloud container clusters get-credentials ${{ env.GKE_CLUSTER }} --zone us-east1-b --project ${{ env.GKE_PROJECT }}
kubectl set image deployment/$GKE_DEPLOYMENT ${{ env.GKE_CONTAINER }}=${{ env.IMAGE }}:${{ env.TAG }}
kubectl rollout status deployment/$GKE_DEPLOYMENT
Surprisingly when I manually run docker push it works fine
Also I am using the similar yaml file to push other projects and they work totally fine. Its just this github action that fails.
Any leads would be appreciated.
Found out that I missed a step and didnt add the Service Account keys in Secrets for Github actions and that led to the failure of this particular actions.

Yii2 deploy using GitHub actions

I was using the following configuration to deploy Yii2 applications with GitHub actions:
name: Build and Deploy - DEV
on:
push:
branches:
- development
jobs:
build:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout#master
- name: Setup Enviroment
uses: shivammathur/setup-php#v2
with:
php-version: '7.2'
- name: Install Packages
run: composer install --no-dev --optimize-autoloader
- name: Deploy to Server
uses: yiier/yii2-base-deploy#master
with:
user: github
host: ${{ host }}
path: ${{ path }}
owner: github
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
- name: Apply migration
run: php yii migrate --interactive=0
It worked quite well, but now is giving this error:
Current runner version: '2.285.1'
Operating System
Virtual Environment
Virtual Environment Provisioner
GITHUB_TOKEN Permissions
Secret source: Actions
Prepare workflow directory
Prepare all required actions
Getting action download info
Error: Unable to resolve action `yiier/yii2-base-deploy#master`, repository not found
Appears that yiier/yii2-base-deploy#master no longer existis.
Anyone knows a replacer?
Thanks!
Thanks to SiZE comment i remember I had fork the original repo.

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 do you set KUBECONFIG to connect to Azure Kubernetes service from github actions deployment?

I am trying to setup a deployment pipeline to configure an Azure Kubernetes service from github actions. I have found steps on the github actions marketplace for configuring various steps however I cannot get any combination of them to work correctly. I keep getting errors saying
error loading config file
"/home/runner/work/_temp/kubeconfig_xxxx": yaml: did not find
expected key
or similar errors saying
error loading config file couldn't get version/kind; json parse error: json: cannot unmarshal array into Go value of type struct { APIVersion string json:"apiVersion,omitempty; Kind string json:\kind,omitempty\ }
depending on how I try to pass the kube_config from Terraform. If I run the same environment locally it works so I am assuming there is something wrong with how it is setup on github actions.
Here is my deployment file:
name: Deploy
on:
workflow_dispatch:
inputs:
<redacted>
jobs:
deploy:
name: Deploy
runs-on: ubuntu-18.04
env:
<redacted>
defaults:
run:
shell: bash
steps:
- uses: actions/checkout#v2
- uses: azure/login#v1.1
with:
creds: ${{ <redacted> }}
- name: Generate Terraform backend
uses: azure/cli#v1.0.3
with:
azcliversion: 2.11.1
inlineScript: |
<redacted>
- uses: hashicorp/setup-terraform#v1.1.0
with:
terraform_version: 0.13.0
- name: Terraform Init
run: |
terraform init
- name: Terraform Plan
run: |
terraform plan \
<redacted>
-out=tfplan
- name: Terraform Apply
run: |
terraform apply \
-auto-approve \
tfplan
- uses: azure/setup-kubectl#v1
with:
version: 'v1.19.2'
- uses: azure/setup-helm#v1
with:
version: 'v3.3.1'
- name: Save Config
run: |
terraform output kube_config > ./aks.yml
- name: Set Env
run: |
echo ::set-env name=XXX::$(cat ./aks.yml)
- uses: azure/k8s-set-context#v1
with:
method: kubeconfig
kubeconfig: "${{ env.XXX }}"
- name: Test
run: |
kubectl get pods -o wide
I have tried setting KUBECONFIG and getting pods in one step using bash and it also fails. Any ideas what I am missing? Thanks in advance!