-
Notifications
You must be signed in to change notification settings - Fork 1
Publish to GHCR workflow #549
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
981dcc5
Add new build targets to 'Makefile'.
nickeskov 2295d45
Add universal 'Dockerfile' for all binares in the repository.
nickeskov c8d949a
Add new publich to GHCR workflow.
nickeskov 7946d8e
Update .github/workflows/publish-to-ghcr.yml
nickeskov 86e1b1e
Fixed copilot issue.
nickeskov 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,108 @@ | ||
| name: Publish Docker Image to GitHub Container Registry | ||
| run-name: Publish branch ${{ github.ref_name }} to tag ${{ inputs.dockerTag }} | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| dockerTag: | ||
| description: 'Docker Tag' | ||
| required: true | ||
| type: string | ||
| default: 'latest' | ||
| container: | ||
| type: choice | ||
| description: 'Container to build and publish.' | ||
| required: true | ||
| options: | ||
| - nodemon | ||
| - nodemon-telegram | ||
| - nodemon-discord | ||
| workflow_call: | ||
| inputs: | ||
| dockerTag: | ||
| description: 'Docker Tag' | ||
| required: true | ||
| type: string | ||
| default: 'latest' | ||
| container: | ||
| type: string | ||
| description: 'Container to build and publish (nodemon, nodemon-telegram, nodemon-discord).' | ||
| required: true | ||
| default: 'nodemon' | ||
|
|
||
| env: | ||
| IMAGE_TAG: ${{ inputs.dockerTag }} | ||
| IMAGE_ARG_APP: ${{ inputs.container }} | ||
| IMAGE_NAME: |- | ||
| ghcr.io/${{ github.repository }}${{ | ||
| case( | ||
| inputs.container == 'nodemon', '', | ||
| inputs.container == 'nodemon-telegram', '-telegram', | ||
| inputs.container == 'nodemon-discord', '-discord', | ||
| '' | ||
| ) | ||
| }} | ||
|
|
||
| permissions: { } | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build and Push Docker Image to GitHub Container Registry | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| attestations: write | ||
| id-token: write | ||
| steps: | ||
| - name: Check inputs | ||
| env: | ||
| IMAGE_ARG_APP: ${{ env.IMAGE_ARG_APP }} | ||
| IMAGE_TAG: ${{ env.IMAGE_TAG }} | ||
| run: | | ||
| echo "$IMAGE_TAG" | grep -E '^[a-zA-Z0-9._-]+$' || exit 1 # check if the docker tag is valid | ||
| echo "$IMAGE_ARG_APP" | grep -E '^(nodemon|nodemon-telegram|nodemon-discord)$' || exit 1 # check if the container name is valid | ||
|
|
||
| - name: Check out code into the Go module directory | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v5 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Login to GitHub Container Registry | ||
| uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up Docker BuildX | ||
| uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 | ||
|
|
||
| - name: Docker Metadata | ||
| id: meta | ||
| uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0 | ||
| with: | ||
| images: ${{ env.IMAGE_NAME }} | ||
| flavor: latest=false | ||
| tags: | | ||
| type=sha | ||
| type=raw,value=${{ env.IMAGE_TAG }} | ||
| labels: | | ||
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | ||
| org.opencontainers.image.licenses=MIT | ||
| org.opencontainers.image.description="Nodemonitoring and alerting tools for Waves Nodes" | ||
|
|
||
| - name: Build and Push Docker Image | ||
| uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v5 | ||
| id: push | ||
| with: | ||
| context: . | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| pull: true | ||
| build-args: 'APP=${{ env.IMAGE_ARG_APP }}' | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
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,56 @@ | ||
| FROM golang:1.26-alpine3.22@sha256:07e91d24f6330432729082bb580983181809e0a48f0f38ecde26868d4568c6ac AS builder | ||
|
alexeykiselev marked this conversation as resolved.
|
||
| ARG DIR=/app | ||
| WORKDIR ${DIR} | ||
|
|
||
| ARG APP=nodemon | ||
| ARG TARGETOS | ||
| ARG TARGETARCH | ||
|
|
||
| RUN apk add --no-cache make git | ||
| # disable cgo for go build | ||
| ENV CGO_ENABLED=0 | ||
|
|
||
| COPY go.mod . | ||
| COPY go.sum . | ||
|
|
||
| RUN go mod download | ||
|
|
||
| # Copy the .git directory and restore the worktree, also handle current possible changes in go.mod and go.sum | ||
| COPY .git .git | ||
| RUN git restore --source=HEAD --worktree . | ||
| COPY go.mod . | ||
| COPY go.sum . | ||
|
|
||
| # Copy the necessary files for building and override the restored worktree | ||
| COPY Makefile . | ||
| COPY cmd . | ||
| COPY pkg . | ||
| COPY internal internal | ||
|
|
||
| RUN make build-$APP-$TARGETOS-$TARGETARCH | ||
|
|
||
|
nickeskov marked this conversation as resolved.
|
||
| FROM alpine:3.23@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11 | ||
| ARG DIR=/app | ||
| ENV TZ=Etc/UTC \ | ||
| APP_USER=appuser | ||
|
|
||
| ARG APP=nodemon | ||
| ARG TARGETOS | ||
| ARG TARGETARCH | ||
|
|
||
| STOPSIGNAL SIGINT | ||
|
|
||
| RUN addgroup -S $APP_USER \ | ||
| && adduser -S $APP_USER -G $APP_USER | ||
|
|
||
| RUN apk add --no-cache bind-tools | ||
|
|
||
| USER $APP_USER | ||
| WORKDIR ${DIR} | ||
| # Considered as a default HTTP API Port, NATS embedded server port | ||
| EXPOSE 8080 | ||
| EXPOSE 4222 | ||
|
|
||
| COPY --from=builder ${DIR}/build/$TARGETOS-$TARGETARCH/$APP ${DIR}/$APP | ||
|
|
||
| ENTRYPOINT ["./$APP"] | ||
|
nickeskov marked this conversation as resolved.
nickeskov marked this conversation as resolved.
|
||
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
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.