This repository was archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
Add MySQL example. #35
Open
Potherca
wants to merge
1
commit into
actions:main
Choose a base branch
from
potherca-contrib:mysql-service
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,68 @@ | ||||||
| name: MySQL Service Example | ||||||
|
|
||||||
| on: | ||||||
| push: | ||||||
| branches: | ||||||
| - main | ||||||
| pull_request: | ||||||
| branches: | ||||||
| - main | ||||||
|
|
||||||
| defaults: | ||||||
| run: | ||||||
| working-directory: ./mysql | ||||||
|
|
||||||
| jobs: | ||||||
| container-job: | ||||||
| runs-on: ubuntu-latest | ||||||
|
|
||||||
| # runs all of the steps inside the specified container rather than on the VM host. | ||||||
| # Because of this the network configuration changes from host based network to a container network. | ||||||
| container: | ||||||
| image: node:10.16-jessie | ||||||
|
|
||||||
| services: | ||||||
| mysql: | ||||||
| image: mysql:5.7 | ||||||
| env: | ||||||
| MYSQL_ALLOW_EMPTY_PASSWORD: yes | ||||||
| ports: | ||||||
| - 3306:3306 | ||||||
| # needed because the mysql container does not provide a healthcheck | ||||||
| options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10 | ||||||
|
|
||||||
| steps: | ||||||
| - uses: actions/checkout@v2 | ||||||
| - run: npm ci | ||||||
| - run: node client.js | ||||||
| env: | ||||||
| # use mysql for the host here because we have specified a container for the job. | ||||||
| # If we were running the job on the VM this would be localhost | ||||||
| MYSQL_HOST: mysql | ||||||
| MYSQL_PORT: ${{ job.services.mysql.ports[3306] }} | ||||||
|
|
||||||
| # Runs all steps on the VM | ||||||
| # The service containers will use host port binding instead of container networking so you access them via localhost rather than the service name | ||||||
| vm-job: | ||||||
| runs-on: ubuntu-latest | ||||||
|
|
||||||
| services: | ||||||
| mysql: | ||||||
| image: mysql:5.7 | ||||||
| env: | ||||||
| MYSQL_ALLOW_EMPTY_PASSWORD: yes | ||||||
| ports: | ||||||
| # will assign a random free host port | ||||||
| - 3306/tcp | ||||||
| # needed because the mysql container does not provide a healthcheck | ||||||
| options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10 | ||||||
|
|
||||||
| steps: | ||||||
| - uses: actions/checkout@v2 | ||||||
| - run: npm ci | ||||||
| - run: node client.js | ||||||
| env: | ||||||
| # use localhost for the host here because we are running the job on the VM. | ||||||
| # If we were running the job on in a container this would be mysql | ||||||
| MYSQL_HOST: localhost | ||||||
| MYSQL_PORT: ${{ job.services.mysql.ports[3306] }} # get randomly assigned published port | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| const mysql = require('mysql'); | ||
|
|
||
| const mysqlConnection = mysql.createConnection({ | ||
| host: process.env.MYSQL_HOST, | ||
| port: process.env.MYSQL_PORT, | ||
| user: 'root', | ||
| password: '', | ||
| database: 'mysql' | ||
| }); | ||
|
|
||
| mysqlConnection.connect(); | ||
|
|
||
| mysqlConnection.query('SELECT NOW()', (err, res) => { | ||
| if (err) throw err | ||
| console.log(res) | ||
| mysqlConnection.end() | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "dependencies": { | ||
| "mysql": "^2.18.1" | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.