From f800ef3b6fe0ac4916fd8d0d5de041b77ee02928 Mon Sep 17 00:00:00 2001 From: Larry Cai Date: Wed, 8 Nov 2023 09:42:57 +0100 Subject: [PATCH] #74, support ghcr.io using github actions * add container package in github * github action is used, which is triggered by tag * tag version is vx.x.x, support pre-release Signed-off-by: Larry Cai --- .github/workflows/docker-image.yml | 52 ++++++++++++++++++++++++++++++ README.md | 20 ++++++++---- 2 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 00000000..9560939a --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,52 @@ +# +name: Create and publish a Docker image + +# Configures this workflow to run every time a change is pushed to the tag called `v` like `v0.2.0`. +on: + push: + tags: + - 'v*' + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + # tag will be semver + latest + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/README.md b/README.md index 1f5869d9..038ea809 100644 --- a/README.md +++ b/README.md @@ -82,15 +82,14 @@ After playing a hand, a link to an analysis page will appear on the home page. T ![image](ben_screenshot.png) -#### Running the Web App using container (Mac & Linux) +#### Running the Web App using container (Linux & Windows WSL2 ...) -Since some tools rely on `.NET` environment, it could be tricky to setup them (using `mono`) in none-Windows environment correctly, recommend to use container env (like `docker`, `podman`) for it. +It could be tricky to setup them all correctly in your environment, container env (like `docker`, `podman`) is another choice. -Later we may provide autogenerated `ghcr.io/lorserker/ben` package, so far build it locally by yourself. It will execute the [start_ben_all.sh](start_ben_all.sh) to start above scripts automatically. +`ghcr.io/lorserker/ben` [container package](https://github.com/lorserker/ben/pkgs/container/ben) is auto generated for each release. Inside it will execute the [start_ben_all.sh](start_ben_all.sh) to start above scripts automatically. ```` -$ podman build -t ben . -$ podman run -it -p 8080:8080 -p 4443:4443 ben +$ podman run --rm -it -p 8080:8080 -p 4443:4443 ghcr.io/lorserker/ben # to stop Reading deals from: /app/src/gamedb Bottle v0.12.25 server starting up (using GeventServer())... Listening on http://0.0.0.0:8080/ @@ -101,7 +100,16 @@ models loaded Listening on port: 4443 ```` -Open browser to access http://localhost:8080/home to play. And if you want to develop it locally, then map code repo into it, `-v $PWD:/app` +Open browser to access http://localhost:8080 to play. + +You can build it locally like below to test local changes. New Mac is ARM based (not x86), you need to build locally as well. + +```` +$ podman build -t ben . +$ podman run --rm -it -p 8080:8080 -p 4443:4443 ben +```` + +If you want to debug in container env, then you need to map code repo into it, `-v $PWD:/app`. ### Tutorials