forked from EVerest/everest-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
119 lines (102 loc) · 3.82 KB
/
build_and_push_csms.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
name: build_and_push_csms
on:
pull_request:
branches:
- main
- upgrade_**
push:
branches:
- main
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
docker-build-and-push-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- csms: maeve
csms_repo: louisg1337/maeve-csms
csms_branch: set_charging_profile
# - csms_dir: citrineos
# csms_repo: https://github.com/citrineos/citrineos-core.git
# csms_branch: feature/everest-demo
steps:
- name: Checkout this repo
uses: actions/checkout@v4
with:
path: everest-demo
- name: Ensure Docker image version is not referencing an existing release
id: docker-image-version-check
shell: bash
run: |
cd everest-demo
if ! [[ -s '.env' ]]; then
echo 'Error: No .env file found.'
exit 1
fi
if ! grep -qE '^TAG=' .env; then
echo 'Error: .env must contain a TAG variable.'
exit 1
fi
source .env
# Fail if any previous Docker image version value matches the one in
# this PR (excluding the current image version).
for commit in $(git --no-pager log --first-parent --format=%H -- .env | tail -n +2); do
if git --no-pager grep -hF "${TAG}" $commit -- .env | grep -qx ${TAG}; then
echo 'Error: The version in .env matches an'
echo ' earlier version on main. Please update the value in'
echo ' .env to a new version.'
exit 1
fi
done
if git show-ref --tags --verify --quiet "refs/tags/v${TAG}"; then
echo "Error: The tag 'v${TAG}' is already a GitHub release."
echo ' Please update the version in .env'
exit 1
else
echo "TAG=${TAG}" >> "${GITHUB_OUTPUT}"
fi
- name: Checkout the CSMS repo
uses: actions/checkout@v4
with:
repository: ${{ matrix.csms_repo }}
ref: ${{ matrix.csms_branch }}
path: ${{ matrix.csms }}-csms
- name: Configure CSMS
id: configure-csms
shell: bash
run: |
pushd ${{ matrix.csms }}-csms
bash ../everest-demo/${{ matrix.csms }}/apply-patches.sh
- name: Build using docker compose
id: build-using-docker-compose
shell: bash
run: |
source .env
echo "Using docker-compose instead of the build-and-push action since we don't have to duplicate the set of services in that case"
pushd ${{ matrix.csms }}-csms
docker compose build
- name: List, tag and push newly built images
id: list-tag-and-push-newly-built-images
shell: bash
run: |
source .env
echo "Before retagging, image list is"
docker image list
# hardcoding the list of containers for now
echo "Retagging {{ $matrix.csms }}-csms-gateway:latest to "
docker tag ${{ matrix.csms }}-csms-gateway:latest ghcr.io/everest/everest-demo/${{ matrix.csms }}-csms-gateway:"${TAG}"
docker tag ${{ matrix.csms }}-csms-gateway:latest ghcr.io/everest/everest-demo/${{ matrix.csms }}-csms-manager:"${TAG}"
echo "After retagging, image list is"
docker image list
- name: Push the images as packages
id: push-the-images-as-packages
shell: bash
run: |
source .env
docker push ghcr.io/everest/everest-demo/${{ matrix.csms }}-csms-gateway:"${TAG}"
docker push ghcr.io/everest/everest-demo/${{ matrix.csms }}-csms-manager:"${TAG}"