-
Notifications
You must be signed in to change notification settings - Fork 0
feat: support publish_server_image to dockerhub automatically (V2) #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3220137
4627432
fbb32aa
95bc766
5d16c12
4f0b0ed
950d245
ed80fea
31bd179
7162472
ab1eae2
47e4b79
813b45b
6fafcfb
b503287
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| name: "Publish server image(latest)" | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 23 * * *' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build_latest: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| REPOSITORY_URL: apache/hugegraph | ||
| BRANCH: master | ||
| IMAGE_URL: hugegraph/hugegraph:latest | ||
| GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | ||
| OWNER: hugegraph | ||
| REPO: actions | ||
| LAST_COMMIT_HASH: ${{vars.LAST_COMMIT_HASH}} | ||
|
|
||
imbajin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| steps: | ||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v2 | ||
|
|
||
| - name: Login to Docker Hub | ||
| uses: docker/login-action@v2 | ||
| with: | ||
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
|
||
| - name: Checkout latest | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| repository: ${{ env.REPOSITORY_URL }} | ||
| ref: ${{ env.BRANCH }} | ||
|
Comment on lines
+33
to
+34
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the difference between
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They do not have real difference, but in Github action docs, it said that: BTW, in "if conditional statement", use ${{ }} seems to be the recommended way, I have fixed it. |
||
| fetch-depth: 2 | ||
|
|
||
| - name: Get current commit-hash | ||
| run: | | ||
| current_commit_hash=$(git rev-parse HEAD) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: seems rename to
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to keep the style same as the one in name "Get current commit-hash"
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
fine, u could update the title style or not |
||
| echo "CURRENT_COMMIT_HASH=$current_commit_hash" >> $GITHUB_ENV | ||
|
|
||
| - name: Check if an update is needed | ||
| run: | | ||
| need_update='false' | ||
| if [[ "$CURRENT_COMMIT_HASH" != "$LAST_COMMIT_HASH" ]]; then | ||
| need_update='true' | ||
imbajin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
| echo "NEED_UPDATE=$need_update" >> $GITHUB_ENV | ||
| # TODO: replace `if` statements for exit if github provide support for exit gracefully, | ||
| # see https://github.com/actions/runner/issues/662 for more details | ||
|
|
||
| - name: Build X86 Image | ||
| if: ${{ env.NEED_UPDATE == 'true' }} | ||
| uses: docker/build-push-action@v4 | ||
| with: | ||
| context: . | ||
| load: true | ||
| tags: ${{ env.IMAGE_URL }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
|
Comment on lines
+59
to
+60
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: check if the docker image cache work well (seems doesn't take effect now?) could fix it in next/another PR, just address it |
||
|
|
||
| - name: Test X86 Image | ||
| if: ${{ env.NEED_UPDATE == 'true' }} | ||
| run: | | ||
| docker images | ||
| docker run -itd --name=graph -p 18080:8080 $IMAGE_URL | ||
| sleep 20s | ||
| curl 0.0.0.0:18080 || exit | ||
| docker ps -a | ||
| sleep 20s | ||
| curl 0.0.0.0:18080 || exit | ||
| docker ps -a | ||
|
|
||
| - name: Build ARM & Push all | ||
| if: ${{ env.NEED_UPDATE == 'true' }} | ||
| uses: docker/build-push-action@v4 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| tags: ${{ env.IMAGE_URL }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
|
|
||
| - name: Updata last commit-hash | ||
| if: ${{ env.NEED_UPDATE == 'true' }} | ||
| run: | | ||
| curl -L -X PATCH \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
| https://api.github.com/repos/$OWNER/$REPO/actions/variables/LAST_COMMIT_HASH \ | ||
| -d '{"name":"LAST_COMMIT_HASH","value":"'"$CURRENT_COMMIT_HASH"'"}' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| name: "Publish server image(release)" | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| branch: | ||
| required: true | ||
| default: '' | ||
| description: 'The branch name should be like *-x.x.x, for example release-1.0.0' | ||
aroundabout marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| jobs: | ||
| build_latest: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| REPOSITORY_URL: apache/hugegraph | ||
| BRANCH: ${{inputs.branch}} | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make all the env.xxx capital letters |
||
|
|
||
| steps: | ||
| - name: Set image_url | ||
| run: | | ||
| image_url=hugegraph/hugegraph:$(echo "${{ inputs.branch }}" | grep -oP '(\d+\.\d+\.\d+)') | ||
aroundabout marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo $image_url && echo "image_url=$image_url" >> $GITHUB_ENV | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v2 | ||
|
|
||
| - name: Login to Docker Hub | ||
| uses: docker/login-action@v2 | ||
| with: | ||
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
|
||
| - name: Checkout latest | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| repository: ${{ env.REPOSITORY_URL }} | ||
| ref: ${{ env.BRANCH }} | ||
| fetch-depth: 2 | ||
|
|
||
| - name: Build X86 Image | ||
| uses: docker/build-push-action@v4 | ||
| with: | ||
| context: . | ||
| load: true | ||
| tags: ${{ env.image_url }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
|
|
||
| - name: Test X86 Image | ||
| run: | | ||
| echo "$image_url" | ||
| docker images | ||
| docker run -itd --name=graph -p 18080:8080 $image_url | ||
| sleep 20s | ||
| curl 0.0.0.0:18080 || exit | ||
| docker ps -a | ||
| sleep 20s | ||
| curl 0.0.0.0:18080 || exit | ||
| docker ps -a | ||
|
|
||
| - name: Build ARM & Push all | ||
| uses: docker/build-push-action@v4 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| tags: ${{ env.image_url }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
Uh oh!
There was an error while loading. Please reload this page.