1
- name : CI/CD Build and Deploy PostgreSQL Docker Image
1
+ name : CI/CD for PostgreSQL Docker
2
2
3
3
on :
4
4
workflow_dispatch :
7
7
description : ' Environment to deploy (Development/Production)'
8
8
required : true
9
9
default : ' development'
10
+ postgres_version :
11
+ description : ' Postgres Version'
12
+ required : true
13
+ default : ' 17'
10
14
11
15
jobs :
12
- build-push-deploy-postgres :
13
- name : Build, Push, and Deploy PostgreSQL Docker Image
16
+ build-and-push :
17
+ name : Build and Push Docker Images for PostgreSQL
14
18
runs-on : ubuntu-latest
15
19
16
20
steps :
17
- # Checkout Postgres Docker repository
21
+ # Checkout Postgres Docker repository into a specific directory
18
22
- name : Checkout Postgres Repository
19
23
uses : actions/checkout@v3
20
24
with :
21
25
repository : trplgit/postgres
22
26
token : ${{ secrets.GITHUB_TOKEN }}
23
- path : postgres
27
+ path : postgres # Checkout into the 'postgres' directory
24
28
25
29
# Set up Docker buildx
26
30
- name : Set up Docker
27
31
uses : docker/setup-buildx-action@v2
32
+ with :
33
+ version : latest
28
34
29
35
# Log in to Azure Container Registry
30
36
- name : Log in to Azure Container Registry
@@ -34,12 +40,18 @@ jobs:
34
40
username : ${{ vars.ACR_USERNAME }}
35
41
password : ${{ secrets.ACR_PASSWORD }}
36
42
37
- # Build and Push PostgreSQL Docker Image
38
- - name : Build and Push PostgreSQL Docker Image
43
+ # Build and Push Postgres Docker Image for PostgreSQL 17
44
+ - name : Build and Push Postgres Docker Image
39
45
run : |
40
46
docker build -f ./postgres/17/alpine3.21/Dockerfile -t ${{ vars.ACR_NAME }}.azurecr.io/${{ inputs.environment }}/trpl-postgres-docker:v17 ./postgres/17/alpine3.21
41
47
docker push ${{ vars.ACR_NAME }}.azurecr.io/${{ inputs.environment }}/trpl-postgres-docker:v17
42
48
49
+ deploy :
50
+ name : Deploy PostgreSQL to Linux VM
51
+ runs-on : ubuntu-latest
52
+ needs : build-and-push
53
+
54
+ steps :
43
55
# Install OpenVPN
44
56
- name : Install OpenVPN
45
57
run : sudo apt-get install -y openvpn
66
78
run : |
67
79
ifconfig | grep tun || (echo "VPN connection failed" && exit 1)
68
80
69
- # Add user to Docker group
81
+ # Add user to Docker group to allow Docker commands without sudo
70
82
- name : Add user to Docker group
71
83
run : |
72
84
sudo usermod -aG docker $USER
77
89
run : |
78
90
echo "${{ secrets.LINUX_VM_PASSWORD_DEVELOPMENT }}" | sudo -S docker network create odoo-postgres-network || echo "Network already exists"
79
91
80
- # Deploy PostgreSQL Docker container to VM
81
- - name : Deploy PostgreSQL Docker Container to VM
92
+ # Deploy Postgres Docker container to VM
93
+ - name : Deploy Postgres Docker Container to VM
82
94
83
95
with :
84
96
host : ${{ vars.LINUX_VM_HOST_DEVELOPMENT }}
91
103
echo "${{ secrets.LINUX_VM_PASSWORD_DEVELOPMENT }}" | sudo -S docker stop postgres-container || true
92
104
echo "${{ secrets.LINUX_VM_PASSWORD_DEVELOPMENT }}" | sudo -S docker rm postgres-container || true
93
105
94
- # Run PostgreSQL container
106
+ # Run Postgres container (PostgreSQL 17)
95
107
echo "${{ secrets.LINUX_VM_PASSWORD_DEVELOPMENT }}" | sudo -S docker run -d --restart always --name postgres-container --network=odoo-postgres-network -e POSTGRES_PASSWORD=mysecretpassword -p 5433:5433 ${{ vars.ACR_NAME }}.azurecr.io/${{ inputs.environment }}/trpl-postgres-docker:v17
96
108
97
109
# Cleanup VPN credentials
0 commit comments