For clarification, To create the package I would create a folder containing profile.d setup.d, Docker file and build.sh (https://github.com/vmware-tanzu-labs/educates-extension-packages/tree/main/packages/tce-0.12) . Then modify the publish-packages.yaml (which is a github workflow and will update automatically on push to main) to deploy them to GHCR (using imgpkg from Carvel)
Note: profile.d is process AFTER setup.d when building packages unlike Workshop repo profile.d -setup.d processing order (as of 10/27/2022)
-
Set Up Package Files
-
Create folder with desired package name
-
Create structure
cd package-name mkdir setup.d profile.d touch setup.d/setup.sh profile.d post-setup.sh touch Dockerfile build.sh
Dockerfile - instructions on building package image build.sh - Script to run on package creation (in container) setup.d & profile.d - Script files to run on workshop start up
-
Complete Dockerfile
Dockerfile
FROM fedora:37 COPY . /opt/packages/package-name/ WORKDIR /opt/packages/package-name RUN ./build.sh
-
When complete build your Docker Image and Run the container to make sure files have been copied correctly
cd packages/package-name docker build -t package-name . docker run -it package-name
-
-
Test scripts in actual workshop
- Add scripts to workshop
workshop/profile.d
&workshop/setup.d
folders to test scripts Note:workshop/profile.d
processed BEFOREworkshop/setup.d
- Run a workshop in a separate terminal/editor & Test that scripts work as expected
make make open-workshop
- Add scripts to workshop
-
When scripts run correctly in workshop terminal and Dockerfile is configured correctly move your scripts to
package-name/profile.d
&package-name/setup.d
keeping in mind the following notes:-
package-name/profile.d
processes AFTERpackage-name/setup.d
during package creation (as of 10/27/2022) -
Environment variables defined in
package-name/profile.d
(notpackage-name/setup.d
)will exist in the workshop terminal (include path) -
Files in
package-name/setup.d
MUST be made executable before publishing (Note: They will not run in workshop otherwise)cd package-name/setup.d; chmod +x $(find . -type f -name "*.sh");
-
Files in
package-name/profild.d
MUST be made readable before publishing (Note: They will not run in workshop otherwise)cd package-name/profile.d; chmod +r $(find . -type f -name "*.sh");
-
Check if file has read permissions:
test -r script.sh && echo $?
(1=false, 0=true) -
Check if file has execute permissions:
test -x script.sh && echo $?
(1=false, 0=true) -
Remove Permisson
chmod -rx script.sh
Note: Educates runs
test -r *.sh
or[ -r *.sh]
(or -x) on specific script files to check if they are readable or executeable befor sourceing or executing. -
-
Files in
package-name/setup.d
MUST have#!/bin/bash
at top of file -
All scripts should start with the following lines (after
#!/bin/bash
if applicable)set -x set -eo pipefail
-
To reference the current directory decrat a local environment variable with value
$(cd "$(dirname $BASH_SOURCE)/.."; pwd)
For example,
PROJECT_DIR=$(cd "$(dirname $BASH_SOURCE)/.."; pwd) # /opt/packages/package-name mkdir -p $PROJECT_DIR/dir-in-workshop
-
-
When packages are ready publish them
In this repo there exists a github action in
.github/workflows/publish-packages.yaml
. This automatically publishes packages to your GitHub Container registry.-
Open
.github/workflows/publish-packages.yaml
in editor -
Add a Job to publish your package called
package-name
by copying the following into the publish-packages.yaml underjobs:
Note: Replace every instance of 'package-name' with your package name.
publish-package-name: name: Publish package-name runs-on: ubuntu-20.04 steps: - name: Check out the repo uses: actions/checkout@v2 - name: Install imgpkg shell: bash run: | wget -nv -O- https://github.com/vmware-tanzu/carvel-imgpkg/releases/download/v0.28.0/imgpkg-linux-amd64 > /tmp/imgpkg chmod 755 /tmp/imgpkg - name: Calculate variables run: | echo "REPOSITORY_SHA7=${GITHUB_SHA::7}" >>${GITHUB_ENV} - name: Build and publish package-name shell: bash run: | packages/package-name/build.sh /tmp/imgpkg push -i ghcr.io/${{github.repository}}/package-name:sha-${REPOSITORY_SHA7} -f packages/postgres-12 --registry-username=${{github.actor}} --registry-password=${{secrets.GITHUB_TOKEN}} /tmp/imgpkg push -i ghcr.io/${{github.repository}}/package-name:latest -f packages/package-name --registry-username=${{github.actor}} --registry-password=${{secrets.GITHUB_TOKEN}}
-
Add, Commit & Push
-
-
See Published Packages & Add to Workshop
-
Open your repository in browser and navigate to teh
Actions
tab. Here you can see your package being build. Specifically, the output ofbuild.sh
. -
Once build you can add to your workshop by adding it to
lab-labName/resources/workshop.yaml
underspec.workshop.packages
.For example,
lab-mdas-base/resources/workshop.yaml
apiVersion: training.educates.dev/v1beta1 kind: Workshop metadata: name: lab-mdas-base spec: ... workshop: image: jdk17-environment:* ... packages: - name: postgres-12 files: - image: url: ghcr.io/morgan-iverson/mdas-packages/postgres-12:latest ...
Note: In this case the package is called
postgres-12
and was created in themorgan-iverson/mdas-packages
repository and is stored atghcr.io/morgan-iverson/mdas-packages/postgres-12:latest
Note: Be sure to use the
:latest
tag so you work have to update tag in thewokrshop.yaml
every time you modify the package files in the package rep (this repo)
-
-
Now you can test with your workshop!
- Find your files in
/opt/packages
in the workshop terminal (in browser) - Make sure your PATH is set with
echo $PATH
- Check log files in workshop terminal at
~/.local/share/workshop/
(Note: Failed processes will have extension.failed
and you can see log in corresponding log file)
- Find your files in
If your workshop is stuck on 'Waiting for deployment...' you will need to find the logs for the workshop
-
Open the terminal on your computer
-
Find your workshop namespace
kubectl get
Note: Your workshop name space will end with
-w##
NOTw##-s###
-
Save your namespace
ns=lab-my-lab-w01
-
Find your workshop pod
kubectl get pod -n $ns
-
Save pod
pod=lab-mdas-base-w02-s001-#####-####
-
Watch pod logs live
kubectl logs $pod -n $ns --follow
Note: Use CNTRL + C to exit log
-
Find what is slowing down or stopping your deployment
- cd into package folder
cd packages/package-name
- Build with docker
docker build -t package .
Make sure all necessary files have been copied in the correct locations. Files that exist in your image will exist in the /opt/package/package-name
folder in your workshop.
- Run Image as Container
<!-- docker run -it --name gemfire $REGISTRY/gemfire-image:latest -->
In setup.d
you can append export statments or aliases to $HOME/.bash_profile
setup.d/setup.sh
echo "export ENV_VAR=value" >> .bash_profile
echo "alias psql='kubectl exec -it $POD_NAME -- psql'" >> .bash_profile