Add build_push.sh

This commit is contained in:
Michel Peterson 2025-04-05 09:12:47 +00:00
parent fc02fc4dc1
commit 2b656d9b22
3 changed files with 45 additions and 1 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@ dev
/ci/bin/*dev* /ci/bin/*dev*
.vagrant .vagrant
hack/* hack/*
!hack/run.sh !hack/run.sh
!hack/build_push.sh

View File

@ -78,6 +78,31 @@ vagrant rsync
vagrant rsync-auto vagrant rsync-auto
``` ```
#### 3. Deploy development version to K8s cluster
Deployment provides a good environment for:
- Final testing in a real world scenario
- Run the final version until included in a release
> [!Note]
> Make sure to do the build on the architecture you will be running it.
> For example, don't build in Apple Silicon if your cluster runs in amd64.
1. Login to your github container registry
```bash
docker login ghcr.io
```
> [!Important]
> Login to the container registry is stored plain text, use a PAT instead of your Github password. [Create a PAT with write:packages](https://github.com/settings/tokens/new?scopes=write:packages).
2. Compile and push to your github container registry.
```bash
./hack/build_push.sh
```
2.
### Best Practices ### Best Practices
- Use devcontainer for day-to-day development and coding - Use devcontainer for day-to-day development and coding

18
hack/build_push.sh Normal file
View File

@ -0,0 +1,18 @@
#!/bin/bash
set -e
set -x
ROOT_DIR="$(dirname "$(realpath "$0")")"
GITHUB_USER=${GITHUB_USER:-$(jq -r '.auths."ghcr.io".auth' ~/.docker/config.json|base64 -d|cut -d':' -f1)}
GITHUB_REPO=${GITHUB_REPO:-$(basename -s ${ROOT_DIR}/../.git $(git remote get-url origin))}
DOCKER_TAG=${DOCKER_TAG:-$(git branch --show-current)-$(git rev-parse --short HEAD)}
if [ -z "${GITHUB_USER}" ]; then
echo "Error: Need to login to ghcr.io ; execute docker login ghcr.io"
exit 1
fi
docker build $ROOT_DIR/.. --push -t ghcr.io/${GITHUB_USER}/${GITHUB_REPO}:${DOCKER_TAG}
echo "Image pushed to ghcr.io/${GITHUB_USER}/${GITHUB_REPO}:${DOCKER_TAG}"