-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (84 loc) · 3.87 KB
/
build-push-docker.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
name: Build and push Docker image
on:
workflow_run:
workflows: NX-CI
types: completed
branches: [main]
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
jobs:
check-skip:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
outputs:
commit_message: ${{ steps.get_commit_message.outputs.commit_message }}
skip_docker: ${{ steps.check_skip_docker.outputs.skip_docker }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get commit message
id: get_commit_message
run: |
commit_message=$(git log -1 --pretty=%B)
commit_message="${commit_message//'%'/'%25'}"
commit_message="${commit_message//$'\n'/' '}"
commit_message="${commit_message//$'\r'/' '}"
echo $commit_message
echo "commit_message=$commit_message" >> $GITHUB_OUTPUT
- name: Check if commit message contains [skip docker]
id: check_skip_docker
run: |
if [[ "${{ steps.get_commit_message.outputs.commit_message }}" =~ "[skip docker]" ]]; then
echo "skip_docker=true" >> $GITHUB_OUTPUT
echo "skip docker found, skipping docker build and push..."
else
echo "skip_docker=false" >> $GITHUB_OUTPUT
fi
build:
needs: [check-skip]
if: ${{ needs.check-skip.outputs.skip_docker != 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}
- name: Free disk space up
run: rm -rf /opt/hostedtoolcache
- name: Install dotenvx
run: curl -sfS https://dotenvx.sh/install.sh | sh
- name: Set short SHA
id: set_short_sha
run: echo "SHORT_SHA=$(echo ${{ github.sha }} | cut -c 1-7)" >> $GITHUB_OUTPUT
- name: 'Create .env file'
run: |
touch .env
echo "# .env created" >> .env
echo "# .env created" >> ./apps/fe/.env
echo "# .env created" >> ./apps/be/.env
echo "# .env created" >> ./containers/be-with-redis/.env
cat .env
- name: Set COMPOSE_TAG as short commit SHA
run: dotenvx set --plain COMPOSE_TAG ${{ steps.set_short_sha.outputs.SHORT_SHA }}
- name: Build and push images with short commit SHA tag
id: build_and_push
run: |
docker compose -f docker-compose.yml build && docker compose -f docker-compose.bundle.yml build
docker compose -f docker-compose.yml push && docker compose -f docker-compose.bundle.yml push
- name: Set COMPOSE_TAG as latest
if: contains(needs.check-skip.outputs.commit_message, '[docker-latest]')
run: dotenvx set --plain COMPOSE_TAG latest
- name: Build and push images with latest tag
id: build_and_push_latest
if: contains(needs.check-skip.outputs.commit_message, '[docker-latest]')
run: |
docker compose -f docker-compose.yml build && docker compose -f docker-compose.bundle.yml build
docker compose -f docker-compose.yml push && docker compose -f docker-compose.bundle.yml push
- name: Remove .env file
run: |
rm .env