Skip to content

Commit 9483fe1

Browse files
committed
dockerize webapp and api
1 parent 6e54e13 commit 9483fe1

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

.github/workflows/cd.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Tiny-URL-CD-Pipeline
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Tiny-URL-CI-Pipeline"] # must match `name:` in ci.yml
6+
types:
7+
- completed
8+
9+
jobs:
10+
build-docker-images:
11+
#if: >
12+
# github.event.workflow_run.conclusion == 'success' &&
13+
#github.event.workflow_run.head_branch == 'main'
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Cache Docker layers
24+
uses: actions/cache@v3
25+
with:
26+
path: /tmp/.buildx-cache
27+
key: ${{ runner.os }}-docker-${{ github.sha }}
28+
restore-keys: |
29+
${{ runner.os }}-docker-
30+
31+
- name: Build API Docker image
32+
run: |
33+
docker build \
34+
--file api/Dockerfile \
35+
--tag your-org/tinyurl-api:main \
36+
--cache-from=type=local,src=/tmp/.buildx-cache \
37+
--cache-to=type=local,dest=/tmp/.buildx-cache \
38+
./api
39+
40+
- name: Build Webapp Docker image
41+
run: |
42+
docker build \
43+
--file webapp/Dockerfile \
44+
--tag your-org/tinyurl-webapp:main \
45+
--cache-from=type=local,src=/tmp/.buildx-cache \
46+
--cache-to=type=local,dest=/tmp/.buildx-cache \
47+
./webapp

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Tiny URL CI Pipeline
1+
name: Tiny-URL-CI-Pipeline
22

33
on:
44
push:

api/src/shorten-url/create-shorten-url/create-shorten-url.controller.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ describe('ShortenUrl controller', () => {
2121
const response = await underTest.shortenUrl({ url: longUrl });
2222

2323
// Extract the unique ID part of the URL
24-
const urlPattern = /^http:\/\/localhost:3000\/([A-Za-z0-9]{10})$/;
24+
const baseUrl = process.env.SHORTENED_BASE_URL;
25+
if (!baseUrl) throw new Error('SHORTENED_BASE_URL is not defined');
26+
27+
const escapedBaseUrl = baseUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // Escape for regex
28+
const urlPattern = new RegExp(`^${escapedBaseUrl}/([A-Za-z0-9]{10})$`);
2529
const match = response?.shortenedUrl.match(urlPattern);
2630

2731
expect(response).not.toBeNull();

webapp/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
99
return (
1010
<html lang="en">
1111
<head>
12-
<title>URL Shortener</title>
12+
<title>TinyURL like application</title>
1313
</head>
1414
<body>
1515
<ThemeProvider theme={theme}>

0 commit comments

Comments
 (0)