Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
06b86de9
Commit
06b86de9
authored
Dec 08, 2015
by
Achilleas Pipinellis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up postgres CI example [ci skip]
parent
149c934a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
45 deletions
+71
-45
doc/ci/services/postgres.md
doc/ci/services/postgres.md
+71
-45
No files found.
doc/ci/services/postgres.md
View file @
06b86de9
#
#
Using PostgreSQL
# Using PostgreSQL
It's possible to use PostgreSQL database test your apps during builds.
As many applications depend on PostgreSQL as their database, you will
eventually need it in order for your tests to run. Below you are guided how to
do this with the Docker and Shell executors of GitLab Runner.
##
# Use PostgreSQL with
Docker executor
##
Use PostgreSQL with the
Docker executor
If you are using our Docker integration you basically have everything already.
If you are using GitLab's Runner with the Docker executor you basically have
everything set up already.
1.
Add this to your
`.gitlab-ci.yml`
:
First, in your
`.gitlab-ci.yml`
add
:
services:
```
yaml
- postgres
services
:
-
postgres
variables:
variables
:
# Configure postgres service (https://hub.docker.com/_/postgres/)
POSTGRES_DB
:
nice_marmot
POSTGRES_DB: hello_world_test
POSTGRES_USER
:
gitlab_runner
POSTGRES_USER: postgres
POSTGRES_PASSWORD
:
"
"
POSTGRES_PASSWORD: ""
```
2.
Configure your application to use the databas
e:
And then configure your application to use PostgreSQL, for exampl
e:
Host: postgres
```
yaml
User: postgres
Host
:
localhost
Password: postgres
User
:
gitlab_runner
Database: hello_world_test
Password
:
Database
:
nice_marmot
```
3.
You can also use any other available on
[
DockerHub
](
https://hub.docker.com/_/postgres/
)
. For example:
`postgres:9.3`
.
You can also use any other docker image available on
[
Docker Hub
][
hub-pg
]
.
For example, to use PostgreSQL 9.3 the service becomes
`postgres:9.3`
.
Example: https://gitlab.com/gitlab-examples/postgres/blob/master/.gitlab-ci.yml
The
`postgres`
image can accept some environment variables. For more details
check the documentation on
[
Docker Hub
][
hub-pg
]
.
##
# Use PostgreSQL with
Shell executor
##
Use PostgreSQL with the
Shell executor
It's possible to use PostgreSQL on manually configured servers that are using GitLab Runner with Shell executor.
You can also use PostgreSQL on manually configured servers that are using
GitLab Runner with the Shell executor.
1.
First install the PostgreSQL server:
First install the PostgreSQL server:
sudo apt-get install -y postgresql postgresql-client libpq-dev
```
bash
sudo
apt-get
install
-y
postgresql postgresql-client libpq-dev
```
2.
Create an
user:
Then create a
user:
# Install the database packages
```
bash
sudo apt-get install -y postgresql postgresql-client libpq-dev
# Login to PostgreSQL
sudo
-u
postgres psql
-d
template1
# Login to PostgreSQL
# Create a user for GitLab Runner that can create databases
sudo -u postgres psql -d template1
# Do not type the 'template1=#', this is part of the prompt
template1
=
# CREATE USER gitlab_runner CREATEDB;
# Create a user for runner
# Create the database & grant all privileges on database
# Do not type the 'template1=#', this is part of the prompt
template1
=
# CREATE DATABASE nice_marmot OWNER gitlab_runner;
template1=# CREATE USER runner CREATEDB;
# Create the database & grant all privileges on database
# Quit the database session
template1=# CREATE DATABASE hello_world_test OWNER runner;
template1
=
# \q
```
# Quit the database session
Try to connect to database:
template1=# \q
3.
Try to connect to database:
```
bash
# Try connecting to the new database with the new user
sudo
-u
gitlab_runner
-H
psql
-d
nice_marmot
# Try connecting to the new database with the new user
# Quit the database session
sudo -u gitlab-runner -H psql -d hello_world_test
nice_marmot>
\q
```
# Quit the database session
Finally, configure your application to use the database:
hello_world_test> \q
4.
Configure your application to use the database:
```
bash
Host: localhost
User: gitlab_runner
Password:
Database: nice_marmot
```
Host: localhost
## Example project
User: runner
Password:
We have set up an
[
Example PostgreSQL Project
][
postgres-example-repo
]
for your
Database: hello_world_test
convenience that runs on
[
GitLab.com
](
https://gitlab.com
)
using our publicly
available
[
shared runners
](
../runners/README.md
)
.
Want to hack on it? Simply fork it, commit and push your changes. Within a few
moments the changes will be picked by a public runner and the build will begin.
[
hub-pg
]:
https://hub.docker.com/_/postgres/
[
postgres-example-repo
]:
https://gitlab.com/gitlab-examples/postgres
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment