Skip to content

Commit

Permalink
#74, support ghcr.io using github actions
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
larrycai committed Nov 8, 2023
1 parent 8b58f8b commit f800ef3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -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<semver>` 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 }}
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 # <CTRL-C> 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/
Expand All @@ -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

Expand Down

0 comments on commit f800ef3

Please sign in to comment.