Skip to content

Commit 767260a

Browse files
committed
-- replicated code
1 parent d27e1e3 commit 767260a

1 file changed

Lines changed: 26 additions & 86 deletions

File tree

.github/workflows/bica-ci.yml

Lines changed: 26 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ jobs:
3131
name: docker-image
3232
path: image.tar
3333

34-
backup-unencrypted:
35-
name: Backup Unencrypted & Show pg_dump
34+
setup-postgres:
35+
name: Setup PostgreSQL with Sample Data
3636
runs-on: ubuntu-latest
3737
needs: build
38+
outputs:
39+
network: bica-net
3840
steps:
39-
- uses: actions/checkout@v4
40-
4141
- name: Download image artifact
4242
uses: actions/download-artifact@v4
4343
with:
@@ -58,12 +58,12 @@ jobs:
5858
-e POSTGRES_DB=mydatabase \
5959
postgres:15
6060
61-
- name: Wait for Postgres to be ready (container-based)
61+
- name: Wait for Postgres to be ready
6262
run: |
6363
for i in {1..30}; do
6464
docker run --rm --network bica-net postgres:15 \
6565
bash -c "PGPASSWORD=mypass pg_isready -h postgres-db -p 5432 -U myuser" && echo "Postgres is ready" && exit 0
66-
echo "Waiting for Postgres..."
66+
echo "Waiting for Postgres... attempt $i"
6767
sleep 2
6868
done
6969
echo "Postgres did not become ready in time"
@@ -81,42 +81,53 @@ jobs:
8181
email TEXT NOT NULL UNIQUE,
8282
created_at TIMESTAMP DEFAULT NOW()
8383
);
84-
8584
CREATE TABLE IF NOT EXISTS posts (
8685
id SERIAL PRIMARY KEY,
8786
user_id INTEGER NOT NULL REFERENCES users(id),
8887
title TEXT NOT NULL,
8988
content TEXT,
9089
published_at TIMESTAMP
9190
);
92-
9391
CREATE TABLE IF NOT EXISTS comments (
9492
id SERIAL PRIMARY KEY,
9593
post_id INTEGER NOT NULL REFERENCES posts(id),
9694
author_name TEXT NOT NULL,
9795
comment TEXT NOT NULL,
9896
created_at TIMESTAMP DEFAULT NOW()
9997
);
100-
10198
INSERT INTO users (username, email) VALUES
10299
('alice', 'alice@example.com'),
103100
('bob', 'bob@example.com'),
104101
('carol', 'carol@example.com')
105102
ON CONFLICT DO NOTHING;
106-
107103
INSERT INTO posts (user_id, title, content, published_at) VALUES
108104
(1, 'First post', 'This is the content of the first post.', NOW() - INTERVAL '5 days'),
109105
(1, 'Second post', 'More content here.', NOW() - INTERVAL '2 days'),
110106
(2, 'Bob''s post', 'Bob writes something interesting.', NOW() - INTERVAL '3 days')
111107
ON CONFLICT DO NOTHING;
112-
113108
INSERT INTO comments (post_id, author_name, comment) VALUES
114109
(1, 'Eve', 'Great post, thanks!'),
115110
(1, 'Mallory', 'I disagree with your point.'),
116111
(3, 'Trent', 'Nice one, Bob!')
117112
ON CONFLICT DO NOTHING;
118113
"
119114
115+
backup-unencrypted:
116+
name: Backup Unencrypted & Show pg_dump
117+
runs-on: ubuntu-latest
118+
needs: [build, setup-postgres]
119+
steps:
120+
- uses: actions/checkout@v4
121+
122+
- name: Download image artifact
123+
uses: actions/download-artifact@v4
124+
with:
125+
name: docker-image
126+
path: .
127+
128+
- name: Load docker image
129+
run: docker load -i image.tar
130+
120131
- name: Prepare backup folder
121132
run: mkdir -p ./backups
122133

@@ -139,7 +150,7 @@ jobs:
139150
run: |
140151
ls -lh ./backups
141152
tar -xzf ./backups/*.tar.gz -C ./backups
142-
cat ./backups/db_backup.sql
153+
head -40 ./backups/db_backup.sql
143154
144155
- name: Cleanup
145156
run: |
@@ -149,7 +160,7 @@ jobs:
149160
backup-encrypted:
150161
name: Backup Encrypted
151162
runs-on: ubuntu-latest
152-
needs: build
163+
needs: [build, setup-postgres]
153164
steps:
154165
- uses: actions/checkout@v4
155166

@@ -162,76 +173,6 @@ jobs:
162173
- name: Load docker image
163174
run: docker load -i image.tar
164175

165-
- name: Create Docker network
166-
run: docker network create bica-net || true
167-
168-
- name: Start PostgreSQL container
169-
run: |
170-
docker run -d --name postgres-db --network bica-net \
171-
-e POSTGRES_USER=myuser \
172-
-e POSTGRES_PASSWORD=mypass \
173-
-e POSTGRES_DB=mydatabase \
174-
postgres:15
175-
176-
- name: Wait for Postgres to be ready (container-based)
177-
run: |
178-
for i in {1..30}; do
179-
docker run --rm --network bica-net postgres:15 \
180-
bash -c "PGPASSWORD=mypass pg_isready -h postgres-db -p 5432 -U myuser" && echo "Postgres is ready" && exit 0
181-
echo "Waiting for Postgres..."
182-
sleep 2
183-
done
184-
echo "Postgres did not become ready in time"
185-
exit 1
186-
187-
- name: Populate database with sample data
188-
run: |
189-
docker run --rm --network bica-net \
190-
-e PGPASSWORD=mypass \
191-
postgres:15 \
192-
psql -h postgres-db -U myuser -d mydatabase -c "
193-
CREATE TABLE IF NOT EXISTS users (
194-
id SERIAL PRIMARY KEY,
195-
username TEXT NOT NULL UNIQUE,
196-
email TEXT NOT NULL UNIQUE,
197-
created_at TIMESTAMP DEFAULT NOW()
198-
);
199-
200-
CREATE TABLE IF NOT EXISTS posts (
201-
id SERIAL PRIMARY KEY,
202-
user_id INTEGER NOT NULL REFERENCES users(id),
203-
title TEXT NOT NULL,
204-
content TEXT,
205-
published_at TIMESTAMP
206-
);
207-
208-
CREATE TABLE IF NOT EXISTS comments (
209-
id SERIAL PRIMARY KEY,
210-
post_id INTEGER NOT NULL REFERENCES posts(id),
211-
author_name TEXT NOT NULL,
212-
comment TEXT NOT NULL,
213-
created_at TIMESTAMP DEFAULT NOW()
214-
);
215-
216-
INSERT INTO users (username, email) VALUES
217-
('alice', 'alice@example.com'),
218-
('bob', 'bob@example.com'),
219-
('carol', 'carol@example.com')
220-
ON CONFLICT DO NOTHING;
221-
222-
INSERT INTO posts (user_id, title, content, published_at) VALUES
223-
(1, 'First post', 'This is the content of the first post.', NOW() - INTERVAL '5 days'),
224-
(1, 'Second post', 'More content here.', NOW() - INTERVAL '2 days'),
225-
(2, 'Bob''s post', 'Bob writes something interesting.', NOW() - INTERVAL '3 days')
226-
ON CONFLICT DO NOTHING;
227-
228-
INSERT INTO comments (post_id, author_name, comment) VALUES
229-
(1, 'Eve', 'Great post, thanks!'),
230-
(1, 'Mallory', 'I disagree with your point.'),
231-
(3, 'Trent', 'Nice one, Bob!')
232-
ON CONFLICT DO NOTHING;
233-
"
234-
235176
- name: Prepare backup folder
236177
run: mkdir -p ./backups
237178

@@ -286,11 +227,10 @@ jobs:
286227
openssl enc -aes-256-cbc -d -pbkdf2 -salt -in "$f" -out "${f%.enc}.tar.gz" -k "$ENCRYPT_PASS"
287228
done
288229
289-
- name: Extract decrypted tarball and show pg_dump
230+
- name: Extract decrypted tarball and show pg_dump
290231
run: |
291232
tar -xzf ./backups/*.tar.gz -C ./backups
292-
cat ./backups/db_backup.sql
293-
233+
head -40 ./backups/db_backup.sql
294234
295235
docker-publish:
296236
name: Push to Docker Hub

0 commit comments

Comments
 (0)