Skip to content

Commit 89a2e85

Browse files
committed
New workflows for image creation and submission added
1 parent 028661f commit 89a2e85

File tree

10 files changed

+216
-19
lines changed

10 files changed

+216
-19
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Docker image creation and push to Dockerhub on merge to main branch
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
jobs:
8+
9+
create-push:
10+
name: Docker Image Build and Push (merge main)
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Log in to Docker Hub
18+
uses: docker/login-action@v2
19+
with:
20+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
21+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
22+
23+
- name: Run create_image script for merge to main
24+
working-directory: ./docker
25+
env:
26+
DOCKERHUB_USER: ${{ secrets.DOCKER_HUB_USERNAME }}
27+
DOCKERHUB_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
28+
run: |
29+
chmod +x ./create_image.sh
30+
./create_image.sh
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Docker image creation and push to Dockerhub on release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
9+
create-push:
10+
name: Docker Image Build and Push (release)
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout release tag
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
ref: ${{ github.event.release.tag_name }}
19+
20+
- name: Log in to Docker Hub
21+
uses: docker/login-action@v2
22+
with:
23+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
24+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
25+
26+
- name: Run create_image script for release
27+
working-directory: ./docker
28+
env:
29+
DOCKERHUB_USER: ${{ secrets.DOCKER_HUB_USERNAME }}
30+
DOCKERHUB_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
31+
RELEASE_TAG: ${{ github.event.release.tag_name }}
32+
run: |
33+
chmod +x ./create_image.sh
34+
./create_image.sh release
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Manual build Docker Image Push
2+
on:
3+
workflow_dispatch:
4+
jobs:
5+
manual-image-push:
6+
name: Manual build Docker Image Push
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v4
12+
13+
- name: Log in to Docker Hub
14+
uses: docker/login-action@v2
15+
with:
16+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
17+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
18+
19+
- name: Run create_image script for manual push
20+
working-directory: ./docker
21+
env:
22+
DOCKERHUB_USER: ${{ secrets.DOCKER_HUB_USERNAME }}
23+
DOCKERHUB_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
24+
BRANCH: ${{ github.ref_name }}
25+
DATETIME: ${{ github.event.workflow_dispatch.inputs.datetime || '' }}
26+
COMMIT_SHA: ${{ github.event.workflow_dispatch.inputs.commit_sha || '' }}
27+
run: |
28+
chmod +x ./create_image.sh
29+
./create_image.sh build

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,5 @@ replay_pid*
113113
*/Thumbs.db
114114

115115
#OpenAPI
116-
docs/api/index.html
116+
docs/api/index.html
117+
docker/.env

docker/create_image.sh

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
#!/bin/bash
22

3+
set -euo pipefail
4+
5+
MODE=${1:-dev} # default dev, options dev, release or build
6+
FILE=""
7+
DOCKERHUB_USER=${DOCKERHUB_USER:-}
8+
DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-}
9+
RELEASE_TAG=${RELEASE_TAG:-}
10+
BRANCH_NAME=${BRANCH:-}
11+
DATETIME=${DATETIME:-$(date +%Y%m%d%H%M%S)}
12+
COMMIT=${COMMIT_SHA:-}
13+
314
# Clear for better debugging of possible errors
415
clear
516

@@ -18,11 +29,37 @@ ng build --configuration production
1829
# Move to docker folder
1930
cd ../docker
2031

21-
# Build container
22-
docker build -t blasetvrtumi/rarecips -f Dockerfile ../
32+
if [ "$MODE" == "release" ] && [ -n "$RELEASE_TAG" ]; then
33+
34+
# Set release tag
35+
MODE=$RELEASE_TAG
36+
37+
# Set compose file
38+
FILE="docker-compose.yml"
39+
40+
# Build container
41+
docker build -f Dockerfile -t "$DOCKERHUB_USER/rarecips:$MODE" -t "$DOCKERHUB_USER/rarecips:latest" ../
42+
43+
# Push image latest
44+
docker push "$DOCKERHUB_USER/rarecips:latest"
45+
46+
else
47+
48+
# Set compose file
49+
FILE="docker-compose-dev.yml"
50+
51+
if [ "$MODE" == "build" ]; then
52+
# Set mode to datetime-commit
53+
MODE="${BRANCH_NAME}-$DATETIME-${COMMIT}"
54+
fi
55+
56+
# Build container
57+
docker build -f Dockerfile -t "$DOCKERHUB_USER/rarecips:$MODE" ../
58+
59+
fi
2360

24-
# Push image
25-
docker push blasetvrtumi/rarecips
61+
# Push main image
62+
docker push "$DOCKERHUB_USER/rarecips:$MODE"
2663

27-
# Up compose
28-
docker-compose -p rarecips up
64+
# Push OCI compose file
65+
docker compose -f $FILE -p rarecips publish "$DOCKERHUB_USER/rarecips:$MODE"

docker/docker-compose-dev.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# In project root:
2+
# docker pull blasetvrtumi/rarecips
3+
# cd docker
4+
# docker-compose -p rarecips up --build
5+
6+
services:
7+
8+
rarecips-app:
9+
10+
container_name: rarecips-app
11+
image: blasetvrtumi/rarecips:dev
12+
ports:
13+
- "8443:8443"
14+
depends_on:
15+
- rarecips-DB
16+
command: ["/bin/sh", "-c", "./wait-for-it.sh rarecips-DB:3306 -- && java -jar /app/rarecips-0.0.1-SNAPSHOT.jar"]
17+
environment:
18+
- SPRING_DATASOURCE_URL=jdbc:mysql://rarecips-DB:3306/rarecips
19+
- SPRING_DATASOURCE_USERNAME="${SPRING_DATASOURCE_USERNAME:-root}"
20+
- SPRING_DATASOURCE_PASSWORD="${SPRING_DATASOURCE_PASSWORD:-password}"
21+
22+
rarecips-DB:
23+
container_name: rarecips-DB
24+
image: mysql:9.0.0
25+
ports:
26+
- "3306:3306"
27+
environment:
28+
- MYSQL_DATABASE=rarecips
29+
- MYSQL_ROOT_PASSWORD="${MYSQL_ROOT_PASSWORD:-password}"
30+
volumes:
31+
- /var/lib/mysql
32+
33+
volumes:
34+
mysql:

docker/docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ services:
88
rarecips-app:
99

1010
container_name: rarecips-app
11-
image: blasetvrtumi/rarecips
11+
image: blasetvrtumi/rarecips:0.1
1212
ports:
1313
- "8443:8443"
1414
depends_on:
1515
- rarecips-DB
16-
command: ["/bin/sh", "-c", "./wait-for-it.sh rarecips-DB:3306 -- && java -jar /app/rarecips-0.0.1-SNAPSHOT.jar"]
16+
command: ["/bin/sh", "-c", "./wait-for-it.sh rarecips-DB:3306 -- && java -jar /app/rarecips-0.1-SNAPSHOT.jar"]
1717
environment:
1818
- SPRING_DATASOURCE_URL=jdbc:mysql://rarecips-DB:3306/rarecips
19-
- SPRING_DATASOURCE_USERNAME=root
20-
- SPRING_DATASOURCE_PASSWORD=password
19+
- SPRING_DATASOURCE_USERNAME="${SPRING_DATASOURCE_USERNAME:-root}"
20+
- SPRING_DATASOURCE_PASSWORD="${SPRING_DATASOURCE_PASSWORD:-password}"
2121

2222
rarecips-DB:
2323
container_name: rarecips-DB
@@ -26,7 +26,7 @@ services:
2626
- "3306:3306"
2727
environment:
2828
- MYSQL_DATABASE=rarecips
29-
- MYSQL_ROOT_PASSWORD=password
29+
- MYSQL_ROOT_PASSWORD="${MYSQL_ROOT_PASSWORD:-password}"
3030
volumes:
3131
- /var/lib/mysql
3232

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ REM Move to docker folder
1515
cd "docker"
1616

1717
REM Build container
18-
docker "build" "-t" "blasetvrtumi\rarecips" "-f" "Dockerfile" "../"
18+
docker build -t blasetvrtumi/rarecips:dev -f Dockerfile ../
1919

20-
REM Push image
21-
docker "push" "blasetvrtumi\rarecips"
20+
REM Push image to dev tag
21+
docker push blasetvrtumi/rarecips:dev
2222

2323
REM Up compose
24-
docker-compose "-p" "rarecips" "up"
24+
docker compose -f docker-compose-dev.yml -p rarecips up -d

docker/local_create_image.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Clear for better debugging of possible errors
4+
clear
5+
6+
# Move to angular folder
7+
cd ../frontend
8+
9+
# Install angular cli globally
10+
npm install -g @angular/cli
11+
12+
# Install dependencies
13+
npm install
14+
15+
# Create production build
16+
ng build --configuration production
17+
18+
# Move to docker folder
19+
cd ../docker
20+
21+
# Build container
22+
docker build -t blasetvrtumi/rarecips:dev -f Dockerfile ../
23+
24+
# Push image to dev tag
25+
docker push blasetvrtumi/rarecips:dev
26+
27+
# Up compose
28+
docker-compose -f docker-compose-dev.yml -p rarecips up -d

frontend/src/app/services/recipe.service.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import { Recipe } from "../models/recipe.model";
55
providedIn: "root"
66
})
77
export class RecipeService {
8+
9+
API_URL = "/api/v1/recipes";
10+
size = 10;
11+
812
constructor() { }
913

10-
async getRecipes(): Promise<Recipe[]> {
11-
const response = await fetch("/api/recipes?order=lastmod&size=4&page=0");
14+
async getRecipes(size: number): Promise<Recipe[]> {
15+
const response = await fetch(`${this.API_URL}?order=lastmod&size=${size}&page=0`);
1216
const data = await response.json();
1317
return data.recipes.map((recipe: any) => ({
1418
id: recipe.id,
@@ -36,7 +40,7 @@ export class RecipeService {
3640
}
3741

3842
async getRecipeById(id: number): Promise<Recipe | null> {
39-
const response = await fetch(`/api/recipes/${id}`);
43+
const response = await fetch(`${this.API_URL}/${id}`);
4044
if (response.status === 404) {
4145
return null;
4246
}

0 commit comments

Comments
 (0)