-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (105 loc) · 4.88 KB
/
kv.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
name: KV Build
on:
workflow_call:
inputs:
env:
required: true
type: string
permissions:
packages: write
contents: read
jobs:
build-kv:
runs-on: ubuntu-latest
# In case of production only run when it is a non-prerelease release
if: ${{ inputs.env != 'production' || (github.event_name == 'release' && !github.event.release.prerelease) }}
defaults:
run:
working-directory: deploy
steps:
- uses: actions/checkout@v4
- name: uv
id: setup-uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.5"
enable-cache: true
cache-dependency-glob: "./deploy/uv.lock"
- name: uv sync
run: uv sync --frozen
# Build config using tiptenbrink/confspawn
- name: Config
run: |
uv run confspawn -c config.toml -s ./build/container/kv -t ./context -e ${{ inputs.env }}
uv run confspawn -c config.toml -s ./build/container/librejson -t ./contextlibrejson -e ${{ inputs.env }}
# Set env from config.toml
- name: Set env.REJSON_VERSION
run: |
export REJSON_VERSION=$(uv run confenv -c config.toml -v kv.redisjson_version)
echo "REJSON_VERSION=$REJSON_VERSION" >> $GITHUB_ENV
# If librejson was previously built and stored in cache, use it
- name: Load cached librejson.so
id: cached-librejson
uses: actions/cache@v4
with:
path: deploy/context/librejson.so
key: rejson_module-${{ env.REJSON_VERSION }}
- name: librejson.so
# If cache was not found, rebuild
# Requires GH login
if: steps.cached-librejson.outputs.cache-hit != 'true'
run: |
echo "${{ github.token }}" | gh auth login --with-token
./contextlibrejson/build_librejson.sh
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
# We use the repo/action token, which has specified access to the package
username: ${{ github.actor}}
password: ${{ github.token }}
# Set up buildx for later build-push-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# *************************************************
# ************** SET CONTAINER TAGS ***************
# *************************************************
##### Set the base env vars we will need
# We uniquely identify a commit with its short SHA
- name: Commit SHA_SHORT
run: echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
# We need to use the image name in each tag, so we set that to an env as well
- name: Image name
run: echo "IMAGE_NM=$(uv run confenv -c config.toml -v kv.image_name -e ${{ inputs.env }})" >> $GITHUB_ENV
##### not-production will get :<env> and :<env>-<commit sha>, production only gets :<commit sha>
##### because for production the 'latest' should only be on a release
- name: Set base env.IMAGE_TAG not production
if: ${{ inputs.env != 'production' }}
run: echo "IMAGE_TAG=$IMAGE_NM:${{ inputs.env }},$IMAGE_NM:${{ inputs.env }}-$SHA_SHORT" >> $GITHUB_ENV
- name: Set base env.IMAGE_TAG for production
if: ${{ inputs.env == 'production' }}
run: echo "IMAGE_TAG=$IMAGE_NM:$SHA_SHORT" >> $GITHUB_ENV
##### we only run on a "release" (with type "published") or a "push" event. those have the following values
##### PUSH RELEASE
##### github.event_name = 'push' github.event_name = 'release'
##### N/A github.event.action = 'published'
##### N/A github.event.release.prerelease = 'true' / 'false'
# for any release, if not production, we want to add the release name after the env
- name: Set env.IMAGE_TAG if release and not production
if: ${{ github.event_name == 'release' && inputs.env != 'production' }}
run: echo "IMAGE_TAG=$IMAGE_TAG,$IMAGE_NM:${{ inputs.env }}-${{ github.event.release.tag_name }}" >> $GITHUB_ENV
# if production, also set latest and the version number without the env
- name: Add production tag if full release and production
if: ${{ github.event_name == 'release' && !github.event.release.prerelease && inputs.env == 'production' }}
run: echo "IMAGE_TAG=$IMAGE_TAG,$IMAGE_NM:${{ github.event.release.tag_name }},$IMAGE_NM:latest" >> $GITHUB_ENV
# ************** END SET CONTAINER TAGS ***************
# Build and push
- name: Build and push
uses: docker/build-push-action@v3
with:
context: deploy/context
# Dockerfile tag
tags: ${{ env.IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha, mode=max
push: ${{ github.event_name != 'pull_request' }}