-
-
Notifications
You must be signed in to change notification settings - Fork 2
102 lines (88 loc) · 2.66 KB
/
build-and-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Build and Publish Docker Images
on:
push:
paths:
- frontend/**
- backend/**
branches:
- master
pull_request:
paths:
- frontend/**
- backend/**
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 23
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build with Gradle (backend)
run: |
cd backend
./gradlew bootJar
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get Commit Hash
id: get_commit_hash
run: echo "hash=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Build and push frontend Docker image to GHCR
uses: docker/build-push-action@v3
with:
context: ./frontend
file: ./frontend/Dockerfile
build-args: |
COMMIT_HASH=${{ env.hash }}
push: true
tags: |
ghcr.io/loudbooks/pastebook-frontend:latest
ghcr.io/loudbooks/pastebook-frontend:${{ env.hash }}
- name: Build and push backend Docker image to GHCR
uses: docker/build-push-action@v3
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: |
ghcr.io/loudbooks/pastebook-backend:latest
ghcr.io/loudbooks/pastebook-backend:${{ env.hash }}
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and push frontend Docker image to Docker Hub
uses: docker/build-push-action@v3
with:
context: ./frontend
build-args: |
COMMIT_HASH=${{ env.hash }}
file: ./frontend/Dockerfile
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/pastebook-frontend:latest
${{ secrets.DOCKER_USERNAME }}/pastebook-frontend:${{ env.hash }}
- name: Build and push backend Docker image to Docker Hub
uses: docker/build-push-action@v3
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/pastebook-backend:latest
${{ secrets.DOCKER_USERNAME }}/pastebook-backend:${{ env.hash }}