Skip to content

Commit

Permalink
Feature/Move to GitHub packages for container images (#8)
Browse files Browse the repository at this point in the history
* Cosmetic code changes (docs mainly)

* Try with GitHub Packages

* Upgrade BCI in Dockerfile of cow-demo to Go 1.23 and SLES 15 SP6

* Update application source README files

* Update READMEs
  • Loading branch information
devpro authored Sep 9, 2024
1 parent 4545d7a commit 9eff022
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 54 deletions.
32 changes: 20 additions & 12 deletions .github/workflows/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: PKG

on:
push:
branches: [ "main" ]
branches:
- "main"
workflow_dispatch:

permissions:
Expand All @@ -29,6 +30,7 @@ jobs:
cow-demo: src/cow-demo/**
rancher-helloworld: src/rancher-helloworld/**
build:
if: ${{ github.ref_name == 'main' }}
runs-on: ubuntu-latest
steps:
- name: Check-out the repository
Expand Down Expand Up @@ -76,8 +78,9 @@ jobs:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
if: ${{ github.ref_name == 'main' }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
Expand All @@ -89,27 +92,32 @@ jobs:
matrix:
app: ${{ fromJSON(needs.changes.outputs.apps) }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout source code
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.CONTAINER_REGITRY_DOMAIN }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
registry: ${{ env.CONTAINER_REGISTRY_DOMAIN }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build container image
run: |
cd src/${{ matrix.app }}
docker build . --tag $IMAGE_FOLDER/${{ matrix.app }}:${{ env.IMAGE_TAG }}
docker build . --tag ${{ env.CONTAINER_REGISTRY_DOMAIN }}/${{ env.IMAGE_FOLDER }}/${{ matrix.app }}:${{ env.IMAGE_TAG }}
- name: Push image to container registry
run: docker push $IMAGE_FOLDER/${{ matrix.app }}:${{ env.IMAGE_TAG }}
run: docker push ${{ env.CONTAINER_REGISTRY_DOMAIN }}/${{ env.IMAGE_FOLDER }}/${{ matrix.app }}:${{ env.IMAGE_TAG }}
- name: Push latest tag to container registry
if: ${{ github.ref_name == 'main' }}
run: |
docker tag $IMAGE_FOLDER/${{ matrix.app }}:${{ env.IMAGE_TAG }} $IMAGE_FOLDER/${{ matrix.app }}:latest
docker push $IMAGE_FOLDER/${{ matrix.app }}:latest
docker tag ${{ env.CONTAINER_REGISTRY_DOMAIN }}/${{ env.IMAGE_FOLDER }}/${{ matrix.app }}:${{ env.IMAGE_TAG }} ${{ env.CONTAINER_REGISTRY_DOMAIN }}/${{ env.IMAGE_FOLDER }}/${{ matrix.app }}:latest
docker push ${{ env.CONTAINER_REGISTRY_DOMAIN }}/${{ env.IMAGE_FOLDER }}/${{ matrix.app }}:latest
env:
CONTAINER_REGITRY_DOMAIN: docker.io
IMAGE_FOLDER: ${{ vars.DOCKERHUB_NAMESPACE }}
CONTAINER_REGISTRY_DOMAIN: ghcr.io
IMAGE_FOLDER: suse
IMAGE_TAG: 1.0.${GITHUB_RUN_ID}
40 changes: 37 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
# Contribution guide

## Code lifecycle
## Code lifecycle management

This git repository follows the Gitflow pattern, so make sure to follow the convention.
### Gitflow

For instance, create a branch `feature/my-change-title` from `develop`, once good enough to be shared and reviewed create a Pull Request targetting `develop`.
This git repository follows the Gitflow pattern, so make sure to follow the convention:

- clone the repository (if not already done)
- make sure you are up-to-date with git pull command
- create a branch `feature/my-change-title` from `develop`
- commit your changes on this feature branch and send them with the git push command
- once the changes are good enough for a review/discussion, create a Pull Request (PR) targetting `develop`
- make sure the checks are all green
- once the PR is validated it will be merged to `develop` (with a squash commit) and the feature branch deleted

Maintainers will regularly create a Pull Request (merge commit) from `develop` (latest quality) to `main` (production/stable).

### CI/CD

Continuous Integration and Continuous Delivery are automated through CI/CD pipelines running as GitHub actions.

The source of the pipeline-as-code are in the `.github/workflows` folder:

- [`ci.yml`](.github/workflows/ci.yml)
- [`pkg.yml`](.github/workflows/pkg.yml)

## Code convention

For bash/shell script files, follow the conventions from [Google Style Guide](https://google.github.io/styleguide/shellguide.html).

The quality will be checked by the CI pipeline.

## Troubleshooting

### Container image creation

Here is how to build and push an image to the registry:

```bash
docker login -u $CONTAINER_REGISTRY_USER -p $CONTAINER_REGISTRY_PASSWD ghcr.io
cd src/cow-demo
docker build . -t ghcr.io/suse/cow-demo:1.0.0
docker push ghcr.io/suse/cow-demo:1.0.0
```
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/SUSE/lab-setup/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/SUSE/lab-setup/actions/workflows/ci.yml)

Welcome! You'll find in this repository some open-source material to setup a lab environment.
Welcome! You'll find in this repository everything needed to setup a lab environment from open-source components.

It is used internally at SUSE but is open to everyone. Feel free to [contribute](CONTRIBUTING.md) and share feedback!

Expand Down Expand Up @@ -43,3 +43,15 @@ helm upgrade --install cow-demo suse-lab-setup/cow-demo --namespace demo
```

Browse the [catalog of Helm charts](charts/README.md).

### Container images

Use the container images we provide for our demonstrations, for instance:

```bash
docker run --rm -p 8080:8080 ghcr.io/suse/cow-demo:1.0.10773428519
```

Open the [web application](http://localhost:8080/) and enjoy the live display!

Browse the [catalog of applications](src/README.md).
9 changes: 5 additions & 4 deletions scripts/rancher/cluster-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#######################################
# List clusters managed by Rancher
# Examples:
# rancher_list_clusters
#######################################
rancher_list_clusters() {
echo "Listing clusters registered in Rancher..."
Expand Down Expand Up @@ -77,11 +79,10 @@ spec:
skipWaitForDeleteTimeoutSeconds: 0
timeout: 120
EOF

sleep 10

rancher_get_clusterid $name
echo "DEBUG CLUSTER_ID=${CLUSTER_ID}"
}

#######################################
Expand All @@ -97,6 +98,7 @@ rancher_get_clusterid() {
local name=$1

CLUSTER_ID=$(kubectl get cluster.provisioning.cattle.io -n fleet-default -o=jsonpath="{range .items[?(@.metadata.name==\"${name}\")]}{.status.clusterName}{end}")
echo "DEBUG CLUSTER_ID=${CLUSTER_ID}"
}

#######################################
Expand All @@ -111,7 +113,6 @@ rancher_get_clusterid() {
rancher_get_clusterregistrationcommand() {
local id=$1

REGISTRATION_COMMAND=$(kubectl get clusterregistrationtoken.management.cattle.io -n $id -o=jsonpath='{.items[*].status.nodeCommand}'
)
REGISTRATION_COMMAND=$(kubectl get clusterregistrationtoken.management.cattle.io -n $id -o=jsonpath='{.items[*].status.nodeCommand}')
echo "DEBUG REGISTRATION_COMMAND=${REGISTRATION_COMMAND}"
}
1 change: 0 additions & 1 deletion scripts/rancher/manager-lifecycle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ rancher_install_withcertmanagerclusterissuer() {
local hostname=$4
local clusterissuer=$5


echo "Installing Rancher..."
helm repo add rancher-${repository} https://releases.rancher.com/server-charts/${repository}
helm repo update
Expand Down
4 changes: 1 addition & 3 deletions scripts/rancher/manager-settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ rancher_update_serverurl() {
local rancherUrl=$1

echo "Sets Rancher URL in settings..."
kubectl patch settings.management.cattle.io server-url --type='merge' --patch '{
"value": "'$rancherUrl'"
}'
kubectl patch settings.management.cattle.io server-url --type='merge' --patch '{ "value": "'$rancherUrl'" }'
}
3 changes: 1 addition & 2 deletions scripts/rancher/user-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ rancher_update_password() {
local currentPassword=$3
local newPassword=$4

# updates password
echo "Updates Rancher user password..."
curl -s -k -H "Authorization: Bearer $token" \
-H 'Content-Type: application/json' \
Expand Down Expand Up @@ -84,4 +83,4 @@ rancher_create_apikey() {
echo "DEBUG API_KEY_RESPONSE=${API_KEY_RESPONSE}"
API_TOKEN=$(echo $API_KEY_RESPONSE | jq -r .token)
sleep 5
}
}
7 changes: 7 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Applications

## Catalog

* [Cow Demo](cow-demo/README.md)
* [Game 2048](game-2048/README.md)
* [Rancher Helloworld](rancher-helloworld/README.md)
4 changes: 2 additions & 2 deletions src/cow-demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#WORKDIR /usr/src/ui/semantic
#RUN npx gulp build

FROM registry.suse.com/bci/golang:1.22 as buildgo
FROM registry.suse.com/bci/golang:1.23 as buildgo
COPY . /go/src
WORKDIR /go/src
RUN go build

FROM registry.suse.com/bci/bci-minimal:15.5 as run
FROM registry.suse.com/bci/bci-minimal:15.6 as run
COPY ./static /static
COPY ./templates /templates
COPY --from=buildgo /go/src/cow-demo /bin/cow-demo
Expand Down
24 changes: 19 additions & 5 deletions src/cow-demo/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Cow Demo Application

[![Docker Image Version](https://img.shields.io/docker/v/suselabsetup/cow-demo?label=Docker)](https://hub.docker.com/r/suselabsetup/cow-demo)

Cow Demo is a nice web application, written in Go, used for demonstrating Kubernetes and load balancing.

💡 This is a hard fork of [oskapt/rancher-demo](https://github.com/oskapt/rancher-demo) who hasn't been updated since 2021.
It also took the updates from [bashofmann/rancher-demo](https://github.com/bashofmann/rancher-demo).

## Presentation

It will create a colored icon for each replica within a ReplicaSet and indicate which one most recently served a response.
Replicas which haven't been heard from will begin to fade out, until after a configurable number of seconds they will disappear.
This is useful for demonstrating scaling up/down an upgraded application.

![screenshot](screenshot.png)
## Configuration

Environment variables:

Expand Down Expand Up @@ -39,6 +39,20 @@ Environment variables:
- chameleons
- cowmeleons

## Quickstart with a container

If you have a container engine running, you can start right away with the image:

```bash
docker run --rm -p 8080:8080 ghcr.io/suse/cow-demo:1.0.10773428519
```

Open the [web application](http://localhost:8080/) and enjoy the interactive display!

## Deploy in an environment

The recommanded way to run the application is to deploy in a Kubernetes cluster with with the [Helm chart](https://github.com/SUSE/lab-setup/tree/main/charts/cow-demo).

## Local development

### How to test
Expand Down Expand Up @@ -88,13 +102,13 @@ The container image is using [SUSE BCI (Base Container Images)](https://registry
Build a local image:

```bash
docker build -t cow-demo:local .
docker build -t cow-demo .
```

Start a container:

```bash
docker run --rm -p 8080:8080 -e COW_COLOR:purple cow-demo:local
docker run --rm -p 8080:8080 -e COW_COLOR:purple cow-demo
```

Open [localhost:8080](http://localhost:8080)
Expand Down
34 changes: 21 additions & 13 deletions src/game-2048/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# 2048 game

[![Docker Image Version](https://img.shields.io/docker/v/suselabsetup/game-2048?label=Docker)](https://hub.docker.com/r/suselabsetup/game-2048)

Let's play 2048 Game web application in a container!
Let's play 2048 game in a browser!

💡 This is a hard fork of [gabrielecirulli/2048](https://github.com/gabrielecirulli/2048) which hasn't been updated since 2017.

## How to edit
## Quickstart with a container

If you have a container engine running, you can start right away with the image:

```bash
docker run --rm -p 8080:80 ghcr.io/suse/game-2048:1.0.10773428519
```

Open the [web application](http://localhost:8080/) and enjoy the game!

## Deploy in an environment

The recommanded way to run the application is to deploy in a Kubernetes cluster with with the [Helm chart](https://github.com/SUSE/lab-setup/tree/main/charts/game-2048).

## Update the application

If you want to modify the CSS, edit the SCSS files present in `style/`: `main.scss` and others. Don't edit the `main.css`, because it's supposed to be generated.

Expand All @@ -18,22 +30,18 @@ sass --unix-newlines --watch style/main.scss

SASS will automatically recompile your css when changed.

## How to run locally
## Run from the sources

Build a new container image:
Build a new image:

```bash
docker build . -t game2048:local --no-cache
docker build . -t game-2048 --no-cache
```

Run a container locally:
Start a container:

```bash
docker run --rm -p 8080:80 game2048:local
docker run --rm -p 8080:80 game-2048
```

Open [localhost:8080](http://localhost:8080) et enjoy 😁

## How to deploy

The recommanded way to deploy and run is through Helm with the [associated chart](https://github.com/devpro/helm-charts/tree/main/charts/game-2048).
Loading

0 comments on commit 9eff022

Please sign in to comment.