fix(unifi): allow for smooth migration (#15327)

**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes  # <!--(issue)-->

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [x] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] 🔃 Refactor of current code

**🧪 How Has This Been Tested?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ Checklist:**

- [ ] ⚖️ My code follows the style guidelines of this project
- [ ] 👀 I have performed a self-review of my own code
- [ ] #️⃣ I have commented my code, particularly in hard-to-understand
areas
- [ ] 📄 I have made corresponding changes to the documentation
- [ ] ⚠️ My changes generate no new warnings
- [ ] 🧪 I have added tests to this description that prove my fix is
effective or that my feature works
- [ ] ⬆️ I increased versions for any altered app according to semantic
versioning

** App addition**

If this PR is an app addition please make sure you have done the
following.

- [ ] 🪞 I have opened a PR on
[truecharts/containers](https://github.com/truecharts/containers) adding
the container to TrueCharts mirror repo.
- [ ] 🖼️ I have added an icon in the Chart's root directory called
`icon.png`

---

_Please don't blindly check all the boxes. Read them and only check
those that apply.
Those checkboxes are there for the reviewer to see what is this all
about and
the status of this PR with a quick glance._

---------

Signed-off-by: Kjeld Schouten <kjeld@schouten-lebbing.nl>
This commit is contained in:
Kjeld Schouten
2023-11-24 19:21:05 +01:00
committed by GitHub
parent 7cfcb1649a
commit 9dea0cee6d
2 changed files with 44 additions and 6 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ sources:
- https://github.com/jacobalberty/unifi-docker
- https://unifi-network.ui.com
type: application
version: 16.0.4
version: 16.0.5
annotations:
truecharts.org/category: Networking
truecharts.org/SCALE-support: "true"
+43 -5
View File
@@ -47,10 +47,20 @@ service:
persistence:
config:
enabled: true
mountPath: "/usr/lib/unifi/olddata"
targetSelector:
main:
main:
mountPath: /usr/lib/unifi/olddata
migrate:
mountPath: /usr/lib/unifi/olddata
data:
enabled: true
mountPath: "/usr/lib/unifi/data"
targetSelector:
main:
main:
mountPath: /usr/lib/unifi/data
migrate:
mountPath: /usr/lib/unifi/data
logs:
enabled: true
mountPath: "/usr/lib/unifi/logs"
@@ -64,11 +74,39 @@ portal:
securityContext:
container:
readOnlyRootFilesystem: false
runAsGroup: 999
runAsUser: 999
runAsGroup: 0
runAsUser: 0
workload:
main:
podSpec:
containers:
main:
env: {}
env:
RUN_CHOWN: true
DB_MONGO_LOCAL: true
initContainers:
migrate:
enabled: true
type: init
imageSelector: alpineImage
command:
- /bin/sh
args:
- -c
- |
newdatadir="/usr/lib/unifi/data"
olddatadir="/usr/lib/unifi/olddata/data"
# Check the dir exists
[ ! -d "$newdatadir" ] && echo "$newdatadir missing" && exit 1
# Check if there is a data/data dir to migrate
[ ! -d "$olddatadir" ] && echo "No $olddatadir dir found. Migration skipped" && exit 0
# Check if the new data dir is empty, ignoring the old data dir
dirs=$(ls -A "$newdatadir" | grep -v "data")
if [ -n "$dirs" ]; then
echo "New data dir is empty. Migrating data one level up"
mv $olddatadir/* $newdatadir || echo "Failed to move data" && exit 1
# Remove the data/data dir
rm -rf $olddatadir
echo "Data migration complete"
fi