Cloud build error - pull access denied for python3 - google-cloud-build

I have set a trigger on Github repo using GCP cloud build.
I get error Error response from daemon: pull access denied for python3, repository does not exist or may require 'docker login': denied: requested access to the resource is denied when deploying.
Following is my cloudbuild.yaml
steps:
- name: 'python:3.8'
entrypoint: python3
args: [ './manage.py','migrate' ]
- name: 'python:3.8'
entrypoint: python3
args: [ './manage.py','collectstatic','--no input' ]
- name: 'gcr.io/cloud-builders/gsutil'
entrypoint: 'bash'
args: [ '-c', 'gsutil rsync -R static/ gs://xyz/static' ]
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: 'bash'
args: [ '-c', 'gcloud config set project project1 && gcloud app deploy' ]

Related

Gradle build fails during test in GitHub workflow, runs successfully on IntelliJ though

If I run just 'gradle build -x test' it runs without error but fails when with test option. It works fine if run locally with IntelliJ.
These are few errors and warning I see in GitHub actions log:
Cannot infer source root(s) for source file '/home/runner/work/idau/idau/src/main/java/se/web/ErrorDto.java'. Supported types are File (directories only), DirectoryTree and SourceDirectorySet
Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'personService' defined in file
: Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener#7accf242] to prepare test instance [se.ConfigTest#6297b4ce]
3905
3906
java.lang.IllegalStateException: Failed to load ApplicationContext
To me it seems issue with env and some plugin but unable pin point that. Tried removing cache and cleaning but did not work out. Posting it here as I haven't find any answer yet.
Here is my workflow script:
steps:
- name: Checkout
id: step1
uses: actions/checkout#master
# with:
# ref: ${{ github.event.pull_request.head.ref }}
# repository: ${{github.event.pull_request.head.repo.full_name }}
# Setup JAVA with specific version
- name: Set up JDK 8
uses: actions/setup-java#v3
with:
cache: gradle
java-version: '8'
distribution: 'adopt'
# Setup Gradle with specific version
- name: Setup Gradle
uses: gradle/gradle-build-action#v2.3.3
with:
gradle-version: 4.10.1
- name: Start PostgreSQL on Ubuntu
run: |
sudo systemctl start postgresql.service
pg_isready
# Create a DB user as per
- name: Create additional user
run: |
chmod og+X /home/runner/
sudo -u postgres psql --command="CREATE USER *** PASSWORD '****';" --command="\du"
# Create database
- name: Create additional database
run: |
sudo -u postgres createdb *** --owner=***;
sudo -u postgres createdb *** --owner=***;
sudo -u postgres psql --command="\l"
# This user is needed as defined in build.gradle
#invalidating the cache
- name: Add git user details and perform gradle prerequisite
run: |
git config --global user.email "${GITHUB_ACTOR}"
git config --global user.name "${GITHUB_ACTOR}#users.noreply.github.com"
echo "current user: ${GITHUB_ACTOR}"
# echo "remove .gradle and generated folder: $(rm -rf .gradle generated)"
# echo "remove all cached .gradle folder: $(rm -rf ~/.gradle)"
# echo "give full rights to gradlew : $(chmod +x ./gradlew)"
echo "gradle version: $(gradle -version)"
- run: gradle clean assemble
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action#v1
# --no-daemon Ensure no Gradle daemons are running anymore when your workflow completes.
- name: Build with Gradle
id: build
uses: gradle/gradle-build-action#v2.3.3
with:
gradle-version: 4.10.1
arguments: build --info --no-daemon
- run: ls -R
- name: Upload build reports
uses: actions/upload-artifact#v3
if: success() || failure()
with:
name: build-reports
path: ./build/reports/

CI/CD using Github Actions and AWS EC2 instance

I have a dockerised fastapi app whith depends on mysql and redis which are all configured in docker-compose.yml. Want to implement a CI/CD using github actions and AWS EC2 instance. My EC2 instance has docker and docker-compose installed. Here are my questions.
What do I do to run the tests that depends on the test db?
How do I implement CD from github actions and AWS EC2 instance?
I might not be clear so please ask some questions for clarification. Thank you.
name: backend-api
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: Set up Python 3.10
uses: actions/setup-python#v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Create .env file for configuration settings.
uses: SpicyPizza/create-envfile#v1.3
with:
envkey_APP_ENV: ${{secrets.APP_ENV}}
envkey_APP_HOST: ${{secrets.APP_HOST}}
envkey_MYSQL_USER: ${{secrets.APP_ENV}}
envkey_PROD_BASE_URL: ${{secrets.MYSQL_USER}}
envkey_DEV_BASE_URL: ${{secrets.APP_ENV}}
envkey_MYSQL_ROOT_PASSWORD: ${{secrets.MYSQL_ROOT_PASSWORD}}
envkey_MYSQL_DATABASE: ${{secrets.MYSQL_DATABASE}}
envkey_PRODUCTION_DB_URI: ${{secrets.PRODUCTION_DB_URI}}
envkey_TEST_DB_URI: ${{secrets.TEST_DB_URI}}
envkey_BASE_URL: ${{secrets.BASE_URL}}
envkey_WALLET_PROVIDER_ACCESS_TOKEN: ${{secrets.WALLET_PROVIDER_ACCESS_TOKEN}}
envkey_S3_BUCKET_NAME: ${{secrets.S3_BUCKET_NAME}}
envkey_S3_ACCESS_SECRET: ${{secrets.S3_ACCESS_SECRET}}
envkey_S3_ACCESS_KEY: ${{secrets.S3_ACCESS_KEY}}
envkey_S3_BUCKET_REGION: ${{secrets.S3_BUCKET_REGION}}
envkey_JWT_SECRET_KEY: ${{secrets.JWT_SECRET_KEY}}
envkey_ETHERSCAN_API_URL: ${{secrets.ETHERSCAN_API_URL}}
envkey_BLOCKCHAIN_API_URL: ${{secrets.BLOCKCHAIN_API_URL}}
envkey_WALLET_PROVIDER_BASE_URL: ${{secrets.WALLET_PROVIDER_BASE_URL}}
envkey_STRATEGY_PROVIDER_BASE_URL: ${{secrets.STRATEGY_PROVIDER_BASE_URL}}
envkey_INDEX_PROVIDER_BASE_URL: ${{secrets.INDEX_PROVIDER_BASE_URL}}
- name: Running Tests with pytest
run: |
pytest
Deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Git pull
env:
AWS_EC2_PEM: ${{ secrets.AWS_EC2_PEM }}
AWS_EC2_PUBLIC_IP: ${{ secrets.AWS_EC2_PUBLIC_IP }}
AWS_EC2_USERNAME: ${{ secrets.AWS_EC2_USERNAME }}
run: |
pwd
echo "$AWS_EC2_PEM" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${AWS_EC2_USERNAME}#${AWS_EC2_PUBLIC_IP}
git checkout main &&
git fetch --all &&
git reset --hard origin/main &&
git pull origin main &&
touch .env
docker-compose up -d --build

How to work with Github Actions without .env file

I'm trying to perform deploy Laravel app to AWS Elastic Beanstalk with Github Actions but I had questions on running Github actions because currently I'm try to avoid upload .env file to my repository.
Below provided the default workflows which generated by Github
name: Laravel
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
laravel-tests:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php#15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '8.0'
- uses: actions/checkout#v3
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Create Database
run: |
mkdir -p database
touch database/database.sqlite
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
run: vendor/bin/phpunit
The generated file showing error
There was 1 failure:
1) Tests\Feature\ExampleTest::test_the_application_returns_a_successful_response
Expected response status code [200] but received 500.
Failed asserting that 200 is identical to 500.
The following exception occurred during the last request:
PDOException: SQLSTATE[HY000]: General error: 1 no such table: users in /home/runner/work/sampleSearch/sampleSearch/vendor/laravel/framework/src/Illuminate/Database/Connection.php:414
So may I know how can I solve this connection issues without upload .env file?

Is there a good way of setting up a serverless-framework build utilizing codebuild to deploy lambda Layers

What I'm trying to do is deploy a repository with the dependencies marked in the aws-abstraction-services-layer and have it build through serverless deploy during the build using codebuild on AWS. Wasn't sure if it was attempted before but would love to find more info on solution someone else may have done themselves.
serverless.yml
provider:
name: aws
runtime: python3.8
region: us-west-1
iamRoleStatements:
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
Resource: "*"
- Effect: Allow
Action:
- cloudformation:DescribeStacks
Resource: "*"
- Effect: Allow
Action:
- lambda:PublishLayerVersion
Resource: "*"
layers:
aws-abstraction-services-layer:
# name: aws-abstraction-services-layer
path: aws-abstraction-layer
plugins:
- serverless-layers
- serverless-python-requirements
buildspec.yml
phases:
install:
runtime-versions:
nodejs: 12
python: 3.8
commands:
- npm install -g serverless
- npm install
- serverless plugin install --name serverless-python-requirements
- pip install requests
build:
commands:
- serverless deploy

Using github secrets in another non-workflow yaml file

Is it possible to access a github secret in a yaml file that's not a workflow or an action yaml file?
For example, I've saved in github the environment secret INFURA_RINKEBY_WSS and I attempt to access it in the following yaml config file for my program.
type: EndpointList
endpoints:
- type: RPCEndpoint
chain_id: 1
network: rinkeby
provider: Infura
url: ${{ secrets.INFURA_RINKEBY_WSS}}
explorer: https://etherscan.io
However, the INFURA_RINKEBY_WSS environment variable I've set in github isn't accessed yet by my yaml config file.
The following is my main.yaml github workflow:
name: Report to eth/usd on rinkeby w/ pytelliot
on: push
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9"]
steps:
- uses: actions/checkout#v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python#v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install telliot-feed-examples
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Move pre-made pytelliot configs to home directory
run: |
cp -r ./config ~/
- name: report :)
run: telliot-examples --legacy-id 1 report --submit-once
env:
PK: ${{ secrets.PK }}
INFURA_RINKEBY_WSS: ${{ secrets.INFURA_RINKEBY_WSS }}
Thanks!

Resources