Skip to content

Commit bce7ead

Browse files
committed
dz
1 parent 0361dac commit bce7ead

1 file changed

Lines changed: 97 additions & 44 deletions

File tree

.github/workflows/bica-ci.yml

Lines changed: 97 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ jobs:
3131
name: docker-image
3232
path: image.tar
3333

34-
setup-postgres:
35-
name: Setup PostgreSQL with Sample Data
34+
35+
backup-unencrypted:
36+
name: Backup Unencrypted & Show pg_dump
3637
runs-on: ubuntu-latest
37-
needs: build
38+
needs: [build]
3839
steps:
40+
- uses: actions/checkout@v4
41+
3942
- name: Download image artifact
4043
uses: actions/download-artifact@v4
4144
with:
@@ -73,47 +76,48 @@ jobs:
7376
-e PGPASSWORD=mypass \
7477
postgres:15 \
7578
psql -h postgres-db -U myuser -d mydatabase -c "
76-
-- (sua SQL aqui)
79+
CREATE TABLE IF NOT EXISTS users (
80+
id SERIAL PRIMARY KEY,
81+
username TEXT NOT NULL UNIQUE,
82+
email TEXT NOT NULL UNIQUE,
83+
created_at TIMESTAMP DEFAULT NOW()
84+
);
85+
86+
CREATE TABLE IF NOT EXISTS posts (
87+
id SERIAL PRIMARY KEY,
88+
user_id INTEGER NOT NULL REFERENCES users(id),
89+
title TEXT NOT NULL,
90+
content TEXT,
91+
published_at TIMESTAMP
92+
);
93+
94+
CREATE TABLE IF NOT EXISTS comments (
95+
id SERIAL PRIMARY KEY,
96+
post_id INTEGER NOT NULL REFERENCES posts(id),
97+
author_name TEXT NOT NULL,
98+
comment TEXT NOT NULL,
99+
created_at TIMESTAMP DEFAULT NOW()
100+
);
101+
102+
INSERT INTO users (username, email) VALUES
103+
('alice', 'alice@example.com'),
104+
('bob', 'bob@example.com'),
105+
('carol', 'carol@example.com')
106+
ON CONFLICT DO NOTHING;
107+
108+
INSERT INTO posts (user_id, title, content, published_at) VALUES
109+
(1, 'First post', 'This is the content of the first post.', NOW() - INTERVAL '5 days'),
110+
(1, 'Second post', 'More content here.', NOW() - INTERVAL '2 days'),
111+
(2, 'Bob''s post', 'Bob writes something interesting.', NOW() - INTERVAL '3 days')
112+
ON CONFLICT DO NOTHING;
113+
114+
INSERT INTO comments (post_id, author_name, comment) VALUES
115+
(1, 'Eve', 'Great post, thanks!'),
116+
(1, 'Mallory', 'I disagree with your point.'),
117+
(3, 'Trent', 'Nice one, Bob!')
118+
ON CONFLICT DO NOTHING;
77119
"
78120
79-
backup-unencrypted:
80-
name: Backup Unencrypted & Show pg_dump
81-
runs-on: ubuntu-latest
82-
needs: [build, setup-postgres]
83-
steps:
84-
- uses: actions/checkout@v4
85-
86-
- name: Download image artifact
87-
uses: actions/download-artifact@v4
88-
with:
89-
name: docker-image
90-
path: .
91-
92-
- name: Load docker image
93-
run: docker load -i image.tar
94-
95-
- name: Create Docker network
96-
run: docker network create bica-net || true
97-
98-
- name: Start PostgreSQL container
99-
run: |
100-
docker run -d --name postgres-db --network bica-net \
101-
-e POSTGRES_USER=myuser \
102-
-e POSTGRES_PASSWORD=mypass \
103-
-e POSTGRES_DB=mydatabase \
104-
postgres:15
105-
106-
- name: Wait for Postgres to be ready
107-
run: |
108-
for i in {1..30}; do
109-
docker run --rm --network bica-net postgres:15 \
110-
bash -c "PGPASSWORD=mypass pg_isready -h postgres-db -p 5432 -U myuser" && echo "Postgres is ready" && exit 0
111-
echo "Waiting for Postgres... attempt $i"
112-
sleep 2
113-
done
114-
echo "Postgres did not become ready in time"
115-
exit 1
116-
117121
- name: Prepare backup folder
118122
run: mkdir -p ./backups
119123

@@ -146,7 +150,7 @@ jobs:
146150
backup-encrypted:
147151
name: Backup Encrypted
148152
runs-on: ubuntu-latest
149-
needs: [build, setup-postgres]
153+
needs: [build]
150154
steps:
151155
- uses: actions/checkout@v4
152156

@@ -181,6 +185,54 @@ jobs:
181185
echo "Postgres did not become ready in time"
182186
exit 1
183187
188+
- name: Populate database with sample data
189+
run: |
190+
docker run --rm --network bica-net \
191+
-e PGPASSWORD=mypass \
192+
postgres:15 \
193+
psql -h postgres-db -U myuser -d mydatabase -c "
194+
CREATE TABLE IF NOT EXISTS users (
195+
id SERIAL PRIMARY KEY,
196+
username TEXT NOT NULL UNIQUE,
197+
email TEXT NOT NULL UNIQUE,
198+
created_at TIMESTAMP DEFAULT NOW()
199+
);
200+
201+
CREATE TABLE IF NOT EXISTS posts (
202+
id SERIAL PRIMARY KEY,
203+
user_id INTEGER NOT NULL REFERENCES users(id),
204+
title TEXT NOT NULL,
205+
content TEXT,
206+
published_at TIMESTAMP
207+
);
208+
209+
CREATE TABLE IF NOT EXISTS comments (
210+
id SERIAL PRIMARY KEY,
211+
post_id INTEGER NOT NULL REFERENCES posts(id),
212+
author_name TEXT NOT NULL,
213+
comment TEXT NOT NULL,
214+
created_at TIMESTAMP DEFAULT NOW()
215+
);
216+
217+
INSERT INTO users (username, email) VALUES
218+
('alice', 'alice@example.com'),
219+
('bob', 'bob@example.com'),
220+
('carol', 'carol@example.com')
221+
ON CONFLICT DO NOTHING;
222+
223+
INSERT INTO posts (user_id, title, content, published_at) VALUES
224+
(1, 'First post', 'This is the content of the first post.', NOW() - INTERVAL '5 days'),
225+
(1, 'Second post', 'More content here.', NOW() - INTERVAL '2 days'),
226+
(2, 'Bob''s post', 'Bob writes something interesting.', NOW() - INTERVAL '3 days')
227+
ON CONFLICT DO NOTHING;
228+
229+
INSERT INTO comments (post_id, author_name, comment) VALUES
230+
(1, 'Eve', 'Great post, thanks!'),
231+
(1, 'Mallory', 'I disagree with your point.'),
232+
(3, 'Trent', 'Nice one, Bob!')
233+
ON CONFLICT DO NOTHING;
234+
"
235+
184236
- name: Prepare backup folder
185237
run: mkdir -p ./backups
186238

@@ -239,6 +291,7 @@ jobs:
239291
run: |
240292
tar -xzf ./backups/*.tar.gz -C ./backups
241293
head -40 ./backups/db_backup.sql
294+
242295
docker-publish:
243296
name: Push to Docker Hub
244297
runs-on: ubuntu-latest
@@ -262,4 +315,4 @@ jobs:
262315
- name: Push image
263316
run: |
264317
docker tag $IMAGE_NAME:$TAG ${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:latest
265-
docker push ${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:latest epa corrige la este codigo para o problema das networks va
318+
docker push ${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:latest

0 commit comments

Comments
 (0)