-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add GitHub Actions workflow for building and publishing Docker images #29
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
186efe2
feat: add GitHub Actions workflow for building and publishing Docker …
CasLubbers cc96258
Update Docker credentials in workflow file
CasLubbers 141256d
feat: directly push to docker
CasLubbers 798a806
feat: login to correct repo
CasLubbers 25807b1
feat: login to correct repo
CasLubbers 6bdfbb9
feat: use driver docker
CasLubbers 864189f
fix: revert using cache repository
CasLubbers 592adc8
fix: use github secret
CasLubbers 028183a
fix: use github secret
CasLubbers 359ff44
fix: use simple docker build and push
CasLubbers 629736d
fix: use simple docker build and push
CasLubbers da4bd9f
fix: use simple docker build and push
CasLubbers 045088d
fix: use simple docker build and push
CasLubbers 3c9aa73
fix: use docker build and push action
CasLubbers 56679f3
fix: set correct tag
CasLubbers 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,119 @@ | ||
| name: Build and publish Docker | ||
| on: | ||
| push: | ||
| branches: | ||
| - '**' | ||
| tags-ignore: | ||
| - '*' | ||
| workflow_dispatch: ~ | ||
| env: | ||
| CACHE_REGISTRY: ghcr.io | ||
| CACHE_REPO: linode/apl-nodejs-helloworld | ||
| REPO: linode/apl-nodejs-helloworld | ||
| DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | ||
| DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }} | ||
| BOT_EMAIL: ${{ vars.BOT_EMAIL }} | ||
| BOT_USERNAME: ${{ vars.BOT_USERNAME }} | ||
| COMMIT_SHA: ${{ github.sha }} | ||
|
|
||
| jobs: | ||
| build-test-cache: | ||
| if: (!contains(github.event.head_commit.message, 'ci skip') && !startsWith(github.ref, 'refs/tags/') && !github.event.act) | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - name: Set env | ||
| run: | | ||
| tag=${GITHUB_REF##*/} | ||
| echo "Creating tag: $tag" | ||
| echo "TAG=$tag" >> $GITHUB_ENV | ||
| if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | ||
| revision=${{ env.COMMIT_SHA }} | ||
| echo "Setting apps revision to: $revision" | ||
| echo "APPS_REVISION=$revision" >> $GITHUB_ENV | ||
| else | ||
| echo "Leaving apps revision empty" | ||
| fi | ||
| git config --global user.email $BOT_EMAIL | ||
| git config --global user.name $BOT_USERNAME | ||
|
|
||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
| - name: Login to Github Packages | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ${{ env.CACHE_REGISTRY }} | ||
| username: ${{ env.BOT_USERNAME }} | ||
| password: '${{ secrets.BOT_TOKEN }}' | ||
|
CasLubbers marked this conversation as resolved.
Outdated
|
||
| - name: CI tests, image build and push tag for main or branch | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| push: true | ||
| build-args: | | ||
| APPS_REVISION=${{ env.APPS_REVISION }} | ||
| context: . | ||
| tags: | | ||
| ${{ env.CACHE_REGISTRY }}/${{ env.CACHE_REPO }}:${{ env.TAG }} | ||
|
|
||
| push-to-docker: | ||
| needs: build-test-cache | ||
| if: always() && ((contains(needs.build-test-cache.result, 'success') && !contains(needs.integration.outputs.started, 'true')) || (contains(needs.integration.result, 'success'))) && !github.event.act && github.actor != 'dependabot[bot]' | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - name: Push to docker hub | ||
|
j-zimnowoda marked this conversation as resolved.
Outdated
|
||
| run: | | ||
| set -u | ||
| TAG=${GITHUB_REF##*/} | ||
| docker login ghcr.io -u $BOT_USERNAME -p ${{ secrets.BOT_TOKEN }} | ||
| image="$CACHE_REGISTRY/$CACHE_REPO:$TAG" | ||
| docker pull $image | ||
| docker tag $image $REPO:$TAG | ||
| docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD | ||
| docker push $REPO:$TAG | ||
| - name: Show me the logic | ||
| run: | | ||
| echo github.ref == ${{ github.ref }} | ||
|
|
||
| release: | ||
| needs: push-to-docker | ||
| if: always() && (startsWith(github.ref, 'refs/heads/releases/') || startsWith(github.ref, 'refs/heads/main')) && startsWith(github.event.head_commit.message, 'chore(release)') && !github.event.act | ||
| runs-on: ubuntu-22.04 | ||
| env: | ||
| COMMIT_MSG: ${{ github.event.head_commit.message }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| - name: Set env | ||
| run: | | ||
| git config --global user.email $BOT_EMAIL | ||
| git config --global user.name $BOT_USERNAME | ||
| - name: Create and push git tag | ||
| id: git_tag | ||
| run: | | ||
| TAG=${GITHUB_REF##*/} | ||
| docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD | ||
| docker pull $REPO:$TAG | ||
| docker tag $REPO:$TAG $REPO:latest | ||
| docker push $REPO:latest | ||
| release_tag=v$(jq -r '.version' < package.json) | ||
| echo tag=$release_tag >> $GITHUB_OUTPUT | ||
| echo "Releasing $REPO:$release_tag" | ||
| docker tag $REPO:$TAG $REPO:$release_tag | ||
| docker push $REPO:$release_tag | ||
| docker login -u $BOT_USERNAME -p '${{ secrets.BOT_TOKEN }}' ghcr.io | ||
| docker tag $REPO:$TAG $CACHE_REGISTRY/$CACHE_REPO:$release_tag | ||
| docker push $CACHE_REGISTRY/$CACHE_REPO:$release_tag | ||
| echo "machine github.com login ${{ env.BOT_USERNAME }} password ${{ secrets.BOT_TOKEN }}" > ~/.netrc | ||
| git tag -am "$COMMIT_MSG" $release_tag && git push --follow-tags | ||
| #Cut the CHANGELOG.md file up to the first occurence of the "### \[[0-9]*" (meaning three #, a space,a square bracket and any number after it) | ||
| sed -n '/### \[[0-9]*/q;p' CHANGELOG.md > NEW_CHANGELOG.md | ||
| - name: Create GitHub release | ||
| uses: ncipollo/release-action@v1.20.0 | ||
| env: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| tag: ${{ steps.git_tag.outputs.tag }} | ||
| name: Release ${{ steps.git_tag.outputs.tag }} | ||
| bodyFile: 'NEW_CHANGELOG.md' | ||
| generateReleaseNotes: true | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.