How to solve [githubActions_BUILD FAILED, Caused by: java.net.SocketTimeoutException at PlainSocketImpl.java] - jdbc

I'm trying to build CI/CD using GitHub Actions and codeDeploy.
I used GitHub secret key for the important information that should not be uploaded on.
But there's error message about JDBC.
Here's my error message and code.
1 test completed, 1 failed
80
FinitApplicationTests > contextLoads() FAILED
81
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:98
82
Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1804
83
Caused by: javax.persistence.PersistenceException at AbstractEntityManagerFactoryBean.java:421
84
Caused by: org.hibernate.exception.JDBCConnectionException at SQLStateConversionDelegate.java:112
85
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException at SQLError.java:174
86
Caused by: com.mysql.cj.exceptions.CJCommunicationsException at NativeConstructorAccessorImpl.java:-2
87
Caused by: java.net.SocketTimeoutException at PlainSocketImpl.java:-2
88
89
90
FAILURE: Build failed with an exception.
91
> Task :test FAILED
92
6 actionable tasks: 6 executed
This is my code.
<deploy.yml>
name: Build and Deploy Spring Boot to AWS EC2
on:
push:
branches: [ main ]
env:
PROJECT_NAME: tikkeul-server
BUCKET_NAME: github-actions-s3-bucket-ec2
CODE_DEPLOY_APP_NAME: codedeploy-app
DEPLOYMENT_GROUP_NAME: codedeploy-deployment-group
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup Java JDK 11
uses: actions/setup-java#v1
with:
java-version: 11
- name: Setup MySQL
uses: samin/mysql-action#v1
with:
character set server: 'utf8'
mysql database: rds
mysql user: admin
mysql password: ${{ secrets.DATABASE_PASSWORD }}
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: Build with Gradle
run: ./gradlew build
shell: bash
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
DATABASE_ID: ${{ secrets.DATABASE_ID }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }}
S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }}
S3_BUCKET: ${{ secrets.S3_BUCKET }}
- name: Make Zip File
run: zip -qq -r ./$GITHUB_SHA.zip .
shell: bash
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials#v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip
- name: Code Deploy
run: aws deploy create-deployment --application-name $CODE_DEPLOY_APP_NAME --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name $DEPLOYMENT_GROUP_NAME --s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip
<application.yml>
spring:
jpa:
properties:
hibernate:
format_sql: 'true'
show_sql: 'true'
database-platform: org.hibernate.dialect.MySQL8Dialect
hibernate:
ddl-auto: update
servlet:
multipart:
maxFileSize: 10MB
maxRequestSize: 10MB
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${DATABASE_URL}
username: ${DATABASE_ID}
password: ${DATABASE_PASSWORD}
...
I'm requesting for your assistance, highly appreciated. Thank you in advance
I checked inbound rules on aws. (able access to my local IP)

Related

GitHub Actions: run test on staging branch after comment on a pull request

I have a github actions workflow that runs my cypress tests after a comment on a pull request. The problem is that it seems to run the cypress tests against the master branch. I want the tests to run against the staging branch. How can I get the tests to run against the staging branch after a comment on a pull request?
Here is what my yaml file currently looks like:
name: Cypress Staging Tests
on:
issue_comment:
types: [created]
jobs:
identify-staging-deploy:
runs-on: ubuntu-latest
name: deploy to staging comment on pr
if: contains(github.event.comment.body, 'Successful Gordon Deploy')
steps:
- name: Github API Request
id: gh_request
uses: octokit/request-action#v2.0.2
with:
route: GET /repos/:repository/pulls/:issue_id
repository: ${{ github.repository }}
issue_id: ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: github secret
- name: Get PR information
id: pr_info
run: |
echo "::set-output name=branch::${{ fromJson(steps.gh_request.outputs.data).head.ref }}"
echo "::set-output name=repo_name::${{ fromJson(steps.gh_request.outputs.data).head.repo.full_name }}"
echo "::set-output name=pr_title::${{ fromJson(steps.gh_request.outputs.data).title }}"
- name: Checkout repo
uses: actions/checkout#v2.3.4
with:
token: dispatch token
repository: ${{ steps.pr_info.outputs.repo_name }}
ref: ${{ steps.pr_info.outputs.branch }}
run-cypress-tests:
needs: identify-staging-deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup Node
uses: actions/setup-node#v3
with:
node-version: 12
- name: Install dependencies
run: yarn ci:setup
- name: Cypress Run
id: cypress-results
uses: cypress-io/github-action#v4
with:
browser: chrome
record: true
env:
CYPRESS_fileConfig: staging
- name: Post PR Comment
if: always()
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository_owner }}/repo_name/issues/${{ github.event.issue.number }}/comments \
-f body='#### Cypress Tests: ${{ steps.cypress-results.outcome }}. See results at ${{ steps.cypress-results.outputs.dashboardUrl }}'
env:
GITHUB_TOKEN: dispatch token

Create multiple github self hosted runner dynamically on same machine for multiple databases

I am looking to create multiple self hosted github runner dynamically for each database on same machine. I am able to create manually but looking to automate this process and wanted to run different runner on different database.
Is there any way to create multiple self hosted github runner dynamically for each database.
name: Deploy AMR Dev
on:
push:
branches:
- dev
env:
APPLICATION_NAME: abc
AWS_REGION: us-west-2
ROLE_SESSION_NAME: CI-amr-dev
permissions:
id-token: write
contents: read # This is required for actions/checkout#v2
jobs:
setup-runner-amr:
runs-on: ubuntu-latest
strategy:
matrix:
schema-runner : [db1,db2]
env:
create-github-runner : ${{matrix.schema-runner}}
permissions:
id-token: write
contents: read
outputs:
gitrunner_label: ${{ steps.create-github-runner.outputs.runner-label }}
gitrunner_label_1: ${{ steps.create-github-runner-1.outputs.runner-label }}
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials#master
with:
role-to-assume: "role to assume"
aws-region: "aws region"
- name: Create self hosted runner action step
uses: abc/action-self-hosted-runner-ecs#v0.0.4
id: create-github-runner
with:
ecs-cluster-name: ${{ secrets.CLUSTER_NAME_AMR }}
task-def: ${{ secrets.TASK_DEF_AMR }}
subnets: ${{ secrets.SUBNET_AMR }}
security-groups: ${{ secrets.SG_AMR }}
- name: Create another self hosted runner action step
uses: abc/action-self-hosted-runner-ecs#v0.0.4
id: create-github-runner-1
with:
ecs-cluster-name: ${{ secrets.CLUSTER_NAME_AMR }}
task-def: ${{ secrets.TASK_DEF_AMR }}
subnets: ${{ secrets.SUBNET_AMR }}
security-groups: ${{ secrets.SG_AMR }}
deploy
needs: [setup]
runs-on: [self-hosted, "${{ needs.setup.outputs.gitrunner_label }}"]
steps:
- run: |
echo "${{needs.setup.outputs.gitrunner_label}}"
2 runner has created for each database but in 2nd job deploy there i can only task and which also not picking up by self hosted runner.
help me to improve the code.

Github action yml keeps failing: Invalid workflow file: .github/workflows/AzureARMDeploy.yml#L13

I have crossed check the syntax below and everything seem to be in order but it keeps failing, could someone please look through this syntax?
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: master
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checout code
uses: actions/checkout#v2
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Set up dependency caching for faster builds
uses: actions/cache#v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Build with dotnet
run: dotnet build --configuration Release
- name: Test
run: dotnet test --no-restore --verbosity normal
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v3
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
- name: Login to Aure
uses: azure/login#v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v3
with:
name: .net-app
- name: Deploy to Azure
uses: azure/CLI#v1
with:
inlineScript: |
...
The deploy job should be an item of the jobs table, you have wrong indentation
try
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: master
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checout code
uses: actions/checkout#v2
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Set up dependency caching for faster builds
uses: actions/cache#v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Build with dotnet
run: dotnet build --configuration Release
- name: Test
run: dotnet test --no-restore --verbosity normal
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v3
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
- name: Login to Aure
uses: azure/login#v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v3
with:
name: .net-app
- name: Deploy to Azure
uses: azure/CLI#v1
with:
inlineScript: |
...

GitHub Action workflow not being interpreted upon merge

I'm attempting to create a GHA workflow and I am getting an error that I'm unsure how to fix as I've implemented this in similar environments before.
name: Deploy Staging
# Controls when the workflow will run
on:
# Triggers the workflow on push events only for the main branch
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
# Run the build job first
build:
name: Build
uses: ./.github/workflows/build.yml
deploy-staging:
name: Staging Deploy
runs-on: ubuntu-latest
environment:
name: staging
needs: [build]
permissions:
id-token: write
contents: read
steps:
- uses: actions/setup-node#v3
with:
node-version: '14'
- name: Download build artifacts
uses: actions/download-artifact#v3
with:
name: buildResult
- name: CDK install
run: npm install -g aws-cdk
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials#v1
with:
role-to-assume: XXXX
aws-region: us-east-1
- name: CDK diff
run: cdk --app . diff staging
- name: CDK deploy
run: cdk --app . deploy staging --require-approval never
- name: Configure DX AWS credentials
uses: aws-actions/configure-aws-credentials#v1
with:
role-to-assume: XXXX
aws-region: us-east-1
role-session-name: "${{ github.actor }}"
- name: Report deployment
uses: XXXX/deployment-tracker-action#v1
if: always()
with:
application-name: XXXX
environment: staging
platform: test
deployment-status: ${{ steps.deploy-workload.outcome == 'success' && 'success' || 'fail' }}
aws-region: us-east-1
XXXX
I don't understand quite where I'm going wrong here but when I merged my actions branch and I attempted to get it to work, I received the following message:
error parsing called workflow "./.github/workflows/build.yml": workflow is not reusable as it is missing a `on.workflow_call` trigger
Below is my build file for reference.
name: Build
# Controls when the workflow will run
on:
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
buildEnvironment:
description: Build Environment
required: false
default: production
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# next build runs lint, don't need a step for it
build:
name: Build
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: '14'
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials#v1
with:
role-to-assume: XXXX
aws-region: us-east-1
role-session-name: "${{ github.actor }}"
- name: Install Dependencies
run: npm install
- name: CDK install
run: npm install -g aws-cdk
- name: CDK build
run: cdk synth
- name: Upload build artifacts
uses: actions/upload-artifact#v3
with:
name: buildResult
path: |
cdk.out
test:
name: Test
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: '14'
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials#v1
with:
role-to-assume: XXXX
aws-region: us-east-1
role-session-name: "${{ github.actor }}"
- name: Install Dependencies
run: npm install
- name: Run tests
run: npm test
If you want to call another workflow (reusable workflow), the workflow you're calling needs to have the trigger workflow_call.
Therefore, in order to resolve your error, change build.yml to:
name: Build
on:
workflow_call:
pull_request:
# etc..

Run build process before copying files

I have the following deploy.yml
name: Deploy
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Copy repository contents via scp
uses: appleboy/scp-action#master
env:
HOST: ${{ secrets.HOST }}
USERNAME: ${{ secrets.USERNAME }}
PORT: ${{ secrets.PORT }}
PASSWORD: ${{ secrets.PASSWORD }}
with:
source: "."
target: "/var/www/html/cnaiapp"
rm: true
- name: Executing remote command
uses: appleboy/ssh-action#develop
with:
host: ${{ secrets.HOST }}
USERNAME: ${{ secrets.USERNAME }}
PORT: ${{ secrets.PORT }}
PASSWORD: ${{ secrets.PASSWORD }}
script: cd /var/www/html/cnaiapp && npm run deploy
However, the master branch has unminified and testing code, that I don't want to have in my VPS. Do you know how could I achieve this? BTW, in order to remove this unnecessary code, I'd need to run the npm run build command.
PS: The npm run deploy command just builds the code and starts the server.
Just add a new step with the run command after checkout:
…
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: build
run: npm run build
- name: Copy repository contents via scp
…

Resources