I am new to Github CI and trying to setup Mysql with a specific username and password to test my Django project as per the below .github/workflow file but when systemctl starts mysql an error occurs:
Run sudo systemctl start mysql.service
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
##[error]Process completed with exit code 1.
is visible in the github actions log. The question is: how can I know what went wrong? Is there a way of viewing the output of journalctl -xe for example... Other ideas welcome.
This is my workflow file:
name: Django CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8]
steps:
- uses: actions/checkout#v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python#v2
with:
python-version: ${{ matrix.python-version }}
- name: Set up MySQL 5.7
uses: mirromutth/mysql-action#master
with:
mysql version: 5.7
mysql database: apis
mysql root password: mypassword
mysql user: myuser
mysql password: myotherpassword
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests
run: |
sudo systemctl start mysql.service
python manage.py test
Related
I'm having issues using mysql as the database for my tests that are running in a Github action. I'm using this as a guide.
I'm getting the following error:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'172.18.0.2' (using password: NO) (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
here is my yaml file:
name: LaravelTest
on:
push:
branches: [ test ]
jobs:
laravel_tests:
runs-on: ubuntu-latest
container:
image: kirschbaumdevelopment/laravel-test-runner:8.1
services:
testdb:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test
MYSQL_ALLOW_EMPTY_PASSWORD: 1
ports:
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout#main
- 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
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Install dependencies
run: npm install
- name: Compile assets
run: npm run dev
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
forge_deploy:
runs-on: ubuntu-latest
needs: laravel_tests
steps:
- name: Make Get Request
uses: satak/webrequest-action#master
with:
url: ${{ secrets.MOMENTUM_TEST_DEPLOY_URL }}
method: GET
UPDATE
I removed this line from my phpunit.xml file:
<env name="DB_HOST" value="testdb"/>
and now I'm getting a different error:
SQLSTATE[HY000] [2002] Connection refused (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
After doing some more googling, I found this post which made me go back and pull out the docker container and try to do it using the mysql service that's already available on ubuntu.
Once I was able to successfully start the service and create a database, I then realized that the steps in my action were copying the .env file, and if it wasn't there, it was copying the .env.example file, which I overlooked, and was getting odd results. Once I realized that it was looking in that file for database connection values, I was able to override them with the env option in the yaml file. So, I finally got it working, and this is my working yaml file for anyone that may run into this at some point:
name: LaravelTest
on:
push:
branches: [ test ]
jobs:
laravel_tests:
runs-on: ubuntu-20.04
env:
DB_CONNECTION: mysql
DB_HOST: localhost
DB_PORT: 3306
DB_DATABASE: testdb
DB_USERNAME: root
DB_PASSWORD: root
steps:
- name: Set up MySQL
run: |
sudo systemctl start mysql
mysql -e 'CREATE DATABASE testdb;' -uroot -proot
mysql -e 'SHOW DATABASES;' -uroot -proot
- uses: actions/checkout#main
- 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
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Install dependencies
run: npm install
- name: Compile assets
run: npm run dev
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
forge_deploy:
runs-on: ubuntu-20.04
needs: laravel_tests
steps:
- name: Make Get Request
uses: satak/webrequest-action#master
with:
url: ${{ secrets.MOMENTUM_TEST_DEPLOY_URL }}
method: GET
GitHub Action keeps telling me the following error: every step must define a uses or run key I think I set the uses or run for each step already. What's the problem?
name: cci-api cicd
on: [push,pull_request]
jobs:
ci-enviroment-setup:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout#v2
- name: Setup Python
uses: actions/setup-python#v2
with:
python-version: '3.x'
architecture: 'x64'
- name: Setup Poetry
- run: |
python -m pip install -U pip
pip install poetry
poetry install
- name: Azure Login
- uses: Azure/login#v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure key vault - Get DB Secrets
uses: Azure/get-keyvault-secrets#v1
with:
keyvault: kv-prt-us-dev
secrets: prt-cet
As other pointed out, each step is required to have either run or uses key:
name: cci-api cicd
on: [push,pull_request]
jobs:
ci-enviroment-setup:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout#v2
- name: Setup Python
uses: actions/setup-python#v2
with:
python-version: '3.x'
architecture: 'x64'
- name: Setup Poetry
# removed - in front of run key
run: |
python -m pip install -U pip
pip install poetry
poetry install
- name: Azure Login
# removed - in front of uses key
uses: Azure/login#v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure key vault - Get DB Secrets
uses: Azure/get-keyvault-secrets#v1
with:
keyvault: kv-prt-us-dev
secrets: prt-cet
I'm trying to clone a repository from GitHub to a remote server.
My solution using appleboy/ssh-action GitHub action was working but I was told the same can be achieved using actions/checkout#v2 GitHub action.
I tried to just change - uses: value to actions/checkout#V2` but then the code doesn't work.
I can't find any templates on how to do it using actions/checkout#v2. Any advice would be much appreciated.
name: deploy to a server on push
on:
push:
branches: [ master ]
jobs:
deploy-to-server:
runs-on: ubuntu-latest
steps:
- uses: appleboy/ssh-action#master
with:
host: 123.132.123.132
username: tomas
key: ${{ secrets.PRIVATE_KEY }}
port: 59666
script:
git clone https://github.com/Tomas-R/website.git
As the documentation of actions/checkout#v2 says
This action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it.
steps:
- name: Checkout the repo
uses: actions/checkout#v2
with:
# This will create a directory named `my-repo` and copy the repo contents to it
# so that you can easily upload it to your remote server
path: my-repo
To copy this checked-out repo to a remote server, you may use scp command as follows.
# Runs a set of commands using the runners shell
- name: Upload repo to remote server
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.PRIVATE_KEY }}"
scp -o StrictHostKeyChecking=no -r -P 59666 my-repo tomas#123.132.123.132:/target/directory
By using the above commands we,
Start ssh-agent and bind it to a known location.
Import the private key from the secret to the ssh-agent.
Copy contents from my-repo to the target directory on your remote server.
This way, the private key is never written to the disk / being exposed.
There is yet another easier way to run scp using the Copy via ssh GitHub action.
- name: Copy folder content recursively to remote
uses: garygrossgarten/github-action-scp#release
with:
local: my-repo
remote: ~/target/directory
host: 123.132.123.132
port: 59666
username: tomas
privateKey: ${{secrets.PRIVATE_KEY}}
I have encountered similar problem.
In my case, problem is this (appleboy/ssh-action#master) action file.
Just replace this action file with other action files from Github Marketplace
I have used LuisEnMarroquin/setup-ssh-action#v2.0.0 action file.
My Workflow File:
name: SSH to Ubuntu EC2
on:
push:
branches:
- main
jobs:
ssh-to-ec2:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v2
- name: Set up SSH key
uses: LuisEnMarroquin/setup-ssh-action#v2.0.0
with:
ORIGIN: ${{ secrets.HOST }}
SSHKEY: ${{ secrets.TEST }}
NAME: production
PORT: 22
USER: ubuntu
- run: ssh production "ls -la;id; echo hehe > h.txt "
Here is my config file.my tests work fine without mysql and successfully stop execution in that case but when running testcases with mysql it just get stuck over here.
name: CI
on: [push, pull_request ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 14.x, 15.x ]
steps:
- uses: actions/checkout#v2
- name: Shutdown Ubuntu MySQL (SUDO)
run: sudo service mysql stop
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- name: Set up MySQL 8.0
uses: mirromutth/mysql-action#master
with:
mysql version: 8.0
mysql database: root
mysql root password: root
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm test
- name: Cancel previous runs of this workflow
uses: styfle/cancel-workflow-action#0.6.0
with:
access_token: ${{ github.token }}
env:
CI: true
I have GitHub repo and I want to use GithubActions to automatically execute unit Tests with every pull request.
I already set up a workflow file:
name: CI
on:
pull_request:
branches: [ master ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
- name: Install
run: npm ci
- name: Linter
run: npm run lint
- name: Build
run: npm run build
- name: Docker
run: docker-compose up -d
- name: Wait / Sleep
uses: jakejarvis/wait-action#v0.1.0
with:
time: '10s'
- run: |
docker ps
cat ./dumps/backup.sql | docker exec -i mysql-development_1 /usr/bin/mysql -u root --password=password
- name: Test
run: npm test
As I need to insert the tables first, I want to insert a dump which does work on my machine with the exact same command used here.
However, the Action fails with this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
read unix #->/var/run/docker.sock: read: connection reset by peer
cat: write error: Broken pipe
##[error]Process completed with exit code 1.
How can I access the database within GithubActions?
docker-compose.yml:
version: '3'
services:
mysql-development:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test_db
ports:
- "3308:3306"
To anyone who might run into the same problem:
https://github.blog/changelog/2020-02-21-github-actions-breaking-change-ubuntu-virtual-environments-will-no-longer-start-the-mysql-service-automatically/
You just need to start the mysql-service manually and perhaps wait for a couple of seconds