1
0
mirror of synced 2026-01-29 21:01:19 -05:00

Merge branch 'main' into patch-1

This commit is contained in:
Martin Lopes
2021-05-13 10:41:57 +10:00
committed by GitHub

View File

@@ -22,7 +22,7 @@ topics:
### Introduction
This guide shows you workflow examples that configure a service container using the Docker Hub `postgres` image. The workflow runs a script to create a PostgreSQL client and populate the client with data. To test that the workflow creates and populates the PostgreSQL client, the script prints the client's data to the console.
This guide shows you workflow examples that configure a service container using the Docker Hub `postgres` image. The workflow runs a script that connects to the PostgreSQL service, creates a table, and then populates it with data. To test that the workflow creates and populates the PostgreSQL table, the script prints the data from the table to the console.
{% data reusables.github-actions.docker-container-os-support %}
@@ -81,10 +81,10 @@ jobs:
run: npm ci
- name: Connect to PostgreSQL
# Runs a script that creates a PostgreSQL client, populates
# the client with data, and retrieves data
# Runs a script that creates a PostgreSQL table, populates
# the table with data, and then retrieves the data.
run: node client.js
# Environment variable used by the `client.js` script to create a new PostgreSQL client.
# Environment variables used by the `client.js` script to create a new PostgreSQL table.
env:
# The hostname used to communicate with the PostgreSQL service container
POSTGRES_HOST: postgres
@@ -141,8 +141,8 @@ steps:
run: npm ci
- name: Connect to PostgreSQL
# Runs a script that creates a PostgreSQL client, populates
# the client with data, and retrieves data
# Runs a script that creates a PostgreSQL table, populates
# the table with data, and then retrieves the data.
run: node client.js
# Environment variable used by the `client.js` script to create
# a new PostgreSQL client.
@@ -204,11 +204,11 @@ jobs:
run: npm ci
- name: Connect to PostgreSQL
# Runs a script that creates a PostgreSQL client, populates
# the client with data, and retrieves data
# Runs a script that creates a PostgreSQL table, populates
# the table with data, and then retrieves the data
run: node client.js
# Environment variable used by the `client.js` script to create
# a new PostgreSQL client.
# Environment variables used by the `client.js` script to create
# a new PostgreSQL table.
env:
# The hostname used to communicate with the PostgreSQL service container
POSTGRES_HOST: localhost
@@ -268,11 +268,11 @@ steps:
run: npm ci
- name: Connect to PostgreSQL
# Runs a script that creates a PostgreSQL client, populates
# the client with data, and retrieves data
# Runs a script that creates a PostgreSQL table, populates
# the table with data, and then retrieves the data
run: node client.js
# Environment variable used by the `client.js` script to create
# a new PostgreSQL client.
# Environment variables used by the `client.js` script to create
# a new PostgreSQL table.
env:
# The hostname used to communicate with the PostgreSQL service container
POSTGRES_HOST: localhost
@@ -286,9 +286,9 @@ steps:
### Testing the PostgreSQL service container
You can test your workflow using the following script, which creates a PostgreSQL client and adds a new table with some placeholder data. The script then prints the values stored in the PostgreSQL client to the terminal. Your script can use any language you'd like, but this example uses Node.js and the `pg` npm module. For more information, see the [npm pg module](https://www.npmjs.com/package/pg).
You can test your workflow using the following script, which connects to the PostgreSQL service and adds a new table with some placeholder data. The script then prints the values stored in the PostgreSQL table to the terminal. Your script can use any language you'd like, but this example uses Node.js and the `pg` npm module. For more information, see the [npm pg module](https://www.npmjs.com/package/pg).
You can modify *client.js* to include any PostgreSQL operations needed by your workflow. In this example, the script creates the PostgreSQL client instance, creates a table, adds placeholder data, then retrieves the data.
You can modify *client.js* to include any PostgreSQL operations needed by your workflow. In this example, the script connects to the PostgreSQL service, adds a table to the `postgres` database, inserts some placeholder data, and then retrieves the data.
{% data reusables.github-actions.service-container-add-script %}
@@ -324,11 +324,11 @@ pgclient.query('SELECT * FROM student', (err, res) => {
});
```
The script creates a new PostgreSQL `Client`, which accepts a `host` and `port` parameter. The script uses the `POSTGRES_HOST` and `POSTGRES_PORT` environment variables to set the client's IP address and port. If `host` and `port` are not defined, the default host is `localhost` and the default port is 5432.
The script creates a new connection to the PostgreSQL service, and uses the `POSTGRES_HOST` and `POSTGRES_PORT` environment variables to specify the PostgreSQL service IP address and port. If `host` and `port` are not defined, the default host is `localhost` and the default port is 5432.
The script creates a table and populates it with placeholder data. To test that the PostgreSQL database contains the data, the script prints the contents of the table to the console log.
The script creates a table and populates it with placeholder data. To test that the `postgres` database contains the data, the script prints the contents of the table to the console log.
When you run this workflow, you should see the following output in the "Connect to PostgreSQL" step confirming you created the PostgreSQL client and added data:
When you run this workflow, you should see the following output in the "Connect to PostgreSQL" step, which confirms that you successfully created the PostgreSQL table and added data:
```
null [ { id: 1,