v2ex / remote

Remote Worker
https://www.v2ex.com/go/dev
MIT License
81 stars 4 forks source link

Add CI to build and push image #21

Closed luxiaba closed 2 years ago

luxiaba commented 2 years ago

related #19

First of all, this is same as that PR about blueprint, I'm not sure if this is what you want, please feel free let me know if not fit. ☺️

  1. Create a Github Token . Github Action should have permission to publish the image, we generate this token first, and make sure it has write:packages permission.

  2. Add token generated on step 1 to remote repo secrets . So that we can use it on Github Action, pls named it as PACKAGES_TOKEN(I call it this in ci.yaml for now).

  3. Merge to run CI.

  4. Push to GHCR by Github Action. If everything is ok, at first time, CI will publish a new private image to GHCR, we can change it to public later.

luxiaba commented 2 years ago

I think for image packaging, we'd better only package code/project related data, and remove sensitive data. Now dockerfile packages a sentive file (IPIP DB file) and that not submmited to git, and also config.py, I think it's maybe a little not convenient for others to run, so I made some changes in the configuration part:

  1. Pull. docker pull ghcr.io/v2ex/remote@latest You can have a try using my image first: docker pull ghcr.io/luxiaba/remote@latest

  2. Run.

    docker run -d --name v2ex-remote \
    -e APP_ENV="PrOd" \
    -v $PATH_TO_PROD_CONFIG:/app/remote/config/prod.py \
    -v $PATH_TO_IPIP_DB:/opt/data/ipip.datx \
    -p 127.0.0.1:5001:5000 \
    $IMAGE_ID
    
    # APP_ENV is case insentive.
    # $PATH_TO_PROD_CONFIG is prod config file path.
    # and $PATH_TO_IPIP_DB, IIRC it's should be map to `/opt/data/ipip.datx` in container.
    # BTW, on the new version of macOS, 5000 is used by system services(airdrop or something) by default.

    If everything is ok, we should can curl it now:

    curl 127.0.0.1:5001/hello
livid commented 2 years ago

A small change is needed.

I will add my Docker Hub username and a personal access token to the secrets.

Then we can push to v2ex/remote on Docker Hub. Code is already open-sourced, so we can also publish it as v2ex/remote on Docker Hub.

livid commented 2 years ago

Two secrets are added:

luxiaba commented 2 years ago

Sure, so we push to both or just to docker hub?

livid commented 2 years ago

Only Docker Hub.

So people can simply:

docker pull v2ex/remote

livid commented 2 years ago

login-action did not work. I have set those as repository secrets:

Screen Shot 2021-12-10 at 5 15 50 AM
luxiaba commented 2 years ago

It's a little strange. Let me check it first.

livid commented 2 years ago

I will try to merge it first. Probably because PR cannot access secrets?

luxiaba commented 2 years ago

Yes, it's ture, success now. 🥳

livid commented 2 years ago

Yes, after merging, it worked!

https://github.com/v2ex/remote/runs/4483982047?check_suite_focus=true