forked from AppFlowy-IO/AppFlowy
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (103 loc) · 4.09 KB
/
docker_ci.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Docker-CI
on:
push:
branches: [docker2]
pull_request:
types: [opened, edited, synchronize, reopened, ready_for_review]
branches: [docker2]
jobs:
build-frontend-app:
concurrency:
group: docker_ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
permissions:
actions: write # necessary to overwrite the cache
steps:
- name: Checkout source code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Restore cache
uses: actions/cache/restore@v3
id: RestoreCache
with:
path: .cargo-cache
key: docker-cargo-cache_${{ runner.os }}
- name: Build the app
id: Build
run: |
# set up the cache
mkdir -p .cargo-cache
# it's necesssary to send the .git folder for git-restore-mtime
sed -i -e 's|^[[:space:]]*\.git[[:space:]/]*||' .gitignore
cd frontend/scripts/docker2-buildfiles
sed -i \
-e 's|^#CI-CACHE-INJECT-MARKER:.*|ARG cargo_target_parent=/appflowy|' \
-e 's|^#CI-CACHE-RETRIEVE-MARKER:.*|COPY --from=builder /appflowy/.cargo-cache /cargo-cache|' \
Dockerfile
cat Dockerfile
uid="$(id -u)"
gid="$(id -g)"
echo "BUILD_UID=$uid" >> "$GITHUB_ENV"
echo "BUILD_GID=$gid" >> "$GITHUB_ENV"
# uses the format which `find -newerat $date` wants
echo "APP_BUILD_START_TIME=$(date -u '+%Y-%m-%d %H:%M:%S')" >> "$GITHUB_ENV"
# --no-cache is necessary due to low disk space within github runners
docker-compose build \
--no-cache \
--build-arg "uid=$uid" \
--build-arg "gid=$gid" \
--progress=plain \
| while read line; do \
if [[ "$line" =~ ^Step[[:space:]] ]]; then \
echo "$(date -u '+%H:%m:%S') | $line"; \
else \
echo "$line"; \
fi; \
done \
# clear the current cache to free up space because it has already been
# used in the build and a new one can be extracted from the
# newly-built image
rm -rf .cargo-cache
- name: Retrieve build cache
id: RetrieveBuildCache
if: ${{ github.ref == 'refs/heads/docker2' && steps.Build.outcome == 'success' }}
run: |
# fetch build artifacts from the Docker image
mkdir .tmp
chown "$BUILD_UID:$BUILD_GID" .tmp
docker run --rm \
-v "$PWD"/.tmp:/cache \
--entrypoint cp appflowy/appflowy:latest -r --preserve=mode,timestamps /cargo-cache /cache
mv .tmp/cargo-cache .cargo-cache
rm -rf .tmp
# clean up stale build artifacts
# artifacts are deemed stale if they were not accessed in the last build
find .cargo-cache -type f -not -newerat "$APP_BUILD_START_TIME" -delete -print
# delete the cache so that it can be updated in the following step
# workaround for https://github.com/actions/cache/issues/342
# workaround for https://github.com/actions/cache/issues/171
- name: Allow for overwriting the current cache
if: ${{
github.ref == 'refs/heads/docker2' &&
steps.Build.outcome == 'success' &&
steps.RetrieveBuildCache.outcome == 'success' &&
steps.RestoreCache.outputs.cache-hit
}}
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
run: |
gh extension install actions/gh-actions-cache
gh actions-cache delete --confirm ${{ steps.RestoreCache.outputs.cache-primary-key }}
- name: Update the cache
if: ${{
github.ref == 'refs/heads/docker2' &&
steps.Build.outcome == 'success' &&
steps.RetrieveBuildCache.outcome == 'success'
}}
uses: actions/cache/save@v3
with:
path: .cargo-cache
key: ${{ steps.RestoreCache.outputs.cache-primary-key }}