forked from maaximal/jottadocker
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Auto update, build, and publish image #19
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
Open
NorskNoobing
wants to merge
17
commits into
bluet:main
Choose a base branch
from
NorskNoobing:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
96d5fa4
Create publish-image.yaml
NorskNoobing 2154ad9
Update publish-image.yaml
NorskNoobing 3796367
Update publish-image.yaml
NorskNoobing e88de3c
Update publish-image.yaml
NorskNoobing 9bea0f3
Update publish-image.yaml
NorskNoobing 5b17ca3
Create update-dockerhub-readme.yaml
NorskNoobing e69fed0
Update publish-image.yaml
NorskNoobing 1f5fd33
Update publish-image.yaml
NorskNoobing c81db0c
add no update check
NorskNoobing 6328d19
add check for blank docker image version var
NorskNoobing c5d939c
add newline to end of file
NorskNoobing 854a183
add docker repo override to readme action
NorskNoobing 9c6e07b
removed trailing space
NorskNoobing e2e5e5b
removed trailing space
NorskNoobing 9b0e72b
change no update to update check
NorskNoobing 126b28d
add relative url completion
NorskNoobing d333c0d
add manual trigger for README update
NorskNoobing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| name: Build and Push Docker Image | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 0 * * 0' # Runs on every Sunday at midnight UTC | ||
| workflow_dispatch: | ||
|
|
||
| env: | ||
| # Default to GitHub repo name, but allows to set a separate docker repo name | ||
| # using GitHub repo secrets. | ||
| DOCKER_REPO: ${{ secrets.DOCKER_REPO || github.repository }} | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| # Checkout the repository | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| # Log in to DockerHub using stored credentials | ||
| - name: Log in to DockerHub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
|
||
| # Add Jottacloud repo in order to get the newest jotta-cli version | ||
| - name: Add Jottacloud repo | ||
| run: | | ||
| set -e | ||
| sudo apt-get update | ||
| sudo curl -fsSL https://repo.jotta.cloud/public.asc -o /usr/share/keyrings/jotta.gpg | ||
| echo "deb [signed-by=/usr/share/keyrings/jotta.gpg] https://repo.jotta.cloud/debian debian main" | sudo tee /etc/apt/sources.list.d/jotta-cli.list | ||
| sudo apt-get update | ||
|
|
||
| # Get the latest available jotta-cli version from APT | ||
| - name: Get latest jotta-cli version | ||
| run: | | ||
| VERSION=$(apt-cache madison jotta-cli | awk '{print $3}' | sort -V | tail -n1) | ||
| if [ -z "$VERSION" ]; then | ||
| echo "Error: Unable to fetch jotta-cli version." | ||
| exit 1 | ||
| fi | ||
| echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
|
|
||
| # Get the latest pushed Docker image version from Docker Hub | ||
| # This uses the tag names, and excludes the "latest" tag | ||
| - name: Get latest published Docker image version | ||
| run: | | ||
| DOCKER_VERSION=$(curl -s "https://registry.hub.docker.com/v2/repositories/${{ env.DOCKER_REPO }}/tags" | \ | ||
| jq -r '.results[].name' | grep -v '^latest$' | awk -F '-' '{print $1}' | sort -V | tail -n1) | ||
| if [ -z "$DOCKER_VERSION" ]; then | ||
| echo "Error: Failed to retrieve latest Docker image version. Exiting." | ||
| exit 1 | ||
| fi | ||
|
Comment on lines
+52
to
+57
|
||
| echo "DOCKER_VERSION=$DOCKER_VERSION" >> $GITHUB_ENV | ||
|
|
||
| # Compare versions; exit early if no update is needed | ||
| - name: Compare versions and decide whether to build | ||
NorskNoobing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| run: | | ||
| if [ "${{ env.VERSION }}" == "${{ env.DOCKER_VERSION }}" ]; then | ||
| echo "UPDATE_IMAGE=false" >> $GITHUB_ENV | ||
| echo "No update needed. Skipping build." | ||
| else | ||
| echo "UPDATE_IMAGE=true" >> $GITHUB_ENV | ||
| echo "New version detected: ${{ env.VERSION }} (Latest Docker version: ${{ env.DOCKER_VERSION }})" | ||
| fi | ||
|
|
||
| # Enable QEMU for multi-platform builds | ||
| - name: Set up QEMU | ||
| if: env.UPDATE_IMAGE == 'true' | ||
| uses: docker/setup-qemu-action@v3 | ||
|
|
||
| # Enable Buildx for advanced Docker builds | ||
| - name: Set up Docker Buildx | ||
| if: env.UPDATE_IMAGE == 'true' | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| # Set date variable for image tags | ||
| - name: Set the date variable | ||
| if: env.UPDATE_IMAGE == 'true' | ||
| run: | | ||
| DATE=$(date +%Y%m%d) # Get the current date in yyyyMMdd format | ||
| echo "DATE=$DATE" >> $GITHUB_ENV | ||
|
|
||
| # Build and push the Docker image for multiple platforms | ||
| - name: Build and push Docker image | ||
| if: env.UPDATE_IMAGE == 'true' | ||
| run: | | ||
| IMAGE_TAG="${{ env.VERSION }}-${{ env.DATE }}" | ||
| docker buildx build --platform linux/amd64,linux/arm64/v8 \ | ||
| -t ${{ env.DOCKER_REPO }}:latest \ | ||
| -t ${{ env.DOCKER_REPO }}:${IMAGE_TAG} \ | ||
| --push . | ||
|
|
||
| # Tag the Git repository with the new version and push the tag | ||
| - name: Tag and push Git version | ||
| if: env.UPDATE_IMAGE == 'true' | ||
| run: | | ||
| IMAGE_TAG="${{ env.VERSION }}-${{ env.DATE }}" | ||
| git config --global user.email "${{ github.actor }}@users.noreply.github.com" | ||
| git config --global user.name "${{ github.actor }}" | ||
| git tag "${IMAGE_TAG}" -a -m "jotta-cli ${{ env.VERSION }}" | ||
| git push --tags | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: Update README on Docker Hub | ||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'README.md' | ||
|
|
||
| jobs: | ||
| update_readme: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@v4 | ||
| - name: Docker Hub Description | ||
| uses: peter-evans/dockerhub-description@v4 | ||
| with: | ||
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
| repository: ${{ secrets.DOCKER_REPO || github.repository }} | ||
| readme-filepath: ./README.md | ||
| short-description: ${{ github.event.repository.description }} | ||
| enable-url-completion: true |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pipeline parsing logic assumes tag format with '-' delimiter but doesn't handle cases where tags might not contain '-'. This could cause
awk -F '-' '{print $1}'to fail or return unexpected results for tags without dashes.