-
-
Notifications
You must be signed in to change notification settings - Fork 2
77 lines (68 loc) · 2.23 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
name: Build and Publish Docker Images
on:
push:
paths:
- frontend/**
- backend/**
branches:
- master
- dev
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
matrix:
component: [frontend, backend]
steps:
- name: Checkout code
uses: actions/checkout@v3
- 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: Set Docker Tags
id: set_tags
run: |
if [ "${{ github.ref_name }}" == "master" ]; then
echo "tag=latest" >> $GITHUB_ENV
elif [ "${{ github.ref_name }}" == "dev" ]; then
echo "tag=dev" >> $GITHUB_ENV
else
echo "Unknown branch: ${{ github.ref_name }}"
exit 1
- name: Build and push Docker image to GHCR
uses: docker/build-push-action@v3
with:
context: ./${{ matrix.component }}
file: ./${{ matrix.component }}/Dockerfile
build-args: |
COMMIT_HASH=${{ env.hash }}
push: true
tags: |
ghcr.io/loudbooks/pastebook-${{ matrix.component }}:${{ env.tag }}
ghcr.io/loudbooks/pastebook-${{ matrix.component }}:${{ 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 Docker image to Docker Hub
uses: docker/build-push-action@v3
with:
context: ./${{ matrix.component }}
file: ./${{ matrix.component }}/Dockerfile
build-args: |
COMMIT_HASH=${{ env.hash }}
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/pastebook-${{ matrix.component }}:${{ env.tag }}
${{ secrets.DOCKER_USERNAME }}/pastebook-${{ matrix.component }}:${{ env.hash }}