From d93aeab251b879535e5311a34fa69e9e469016a0 Mon Sep 17 00:00:00 2001 From: Alex Savin Date: Fri, 15 Aug 2025 13:07:08 -0400 Subject: [PATCH] Add CI workflow for building and pushing Docker images --- .github/workflows/CI.yml | 144 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 .github/workflows/CI.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..05469d5 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,144 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - develop + paths-ignore: + - 'README.md' + pull_request: + branches: + - develop + paths-ignore: + - 'README.md' + workflow_dispatch: + branches: + - develop + paths-ignore: + - 'README.md' + +jobs: + + testing: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: + - 1.25.x + os: + - ubuntu-latest + steps: + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + - uses: actions/checkout@v4 + - run: | + go get -u . + go test ./... + + build-and-push: + runs-on: ubuntu-latest + needs: [ testing ] + steps: + + - name: Extract Version + id: version_step + run: | + echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT + echo REPO_VERSION=${GITHUB_REF_NAME#v} >> $GITHUB_OUTPUT + echo RELEASE_DATE=$(date --rfc-3339=date) >> ${GITHUB_ENV} + echo COMMIT_SHA_SHORT=$(echo ${{ github.sha }} | cut -c1-10) >> $GITHUB_OUTPUT + + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + + - name: Dump job context + env: + JOB_CONTEXT: ${{ toJson(job) }} + run: echo "$JOB_CONTEXT" + + - name: Dump steps context + env: + STEPS_CONTEXT: ${{ toJson(steps) }} + run: echo "$STEPS_CONTEXT" + # echo "##[set-output name=version;]VERSION=${GITHUB_REF#$"refs/tags/v"}" + # echo "##[set-output name=version_tag;]$GITHUB_REPOSITORY:${GITHUB_REF#$"refs/tags/v"}" + # echo "##[set-output name=latest_tag;]$GITHUB_REPOSITORY:latest" + # - name: Print Version + # run: | + # echo ${{steps.version_step.outputs.version_tag}} + # echo ${{steps.version_step.outputs.latest_tag}} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker BuildX + uses: docker/setup-buildx-action@v3 + with: + platforms: | + linux/amd64 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + registry: git.savin.nyc + username: ${{ github.repository_owner }} + password: ${{ secrets.GHA_CI_CD_REGISTRY }} + # - name: PrepareReg Names + # id: read-docker-image-identifiers + # run: | + # echo VERSION_TAG=$(echo ${{ steps.version_step.outputs.version_tag }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV + # echo LASTEST_TAG=$(echo ${{ steps.version_step.outputs.latest_tag }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV + + - name: Build and Push + id: docker_build + uses: docker/build-push-action@v6 + with: + # context: . + # file: ./Dockerfile + platforms: | + linux/amd64 + push: true + tags: | + git.savin.nyc/${{ github.repository_owner }}/${{ github.event.repository.name }}:nightly + git.savin.nyc/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.version_step.outputs.COMMIT_SHA_SHORT }} +# ${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }} +# latest + build-args: | + NAME=${{ github.event.repository.name }} + VERSION=${{ steps.version_step.outputs.REPO_VERSION }} + BUILD_DATE=${{ github.event.repository.pushed_at }} + VENDOR="savin.nyc" +# tags: | +# ${{env.VERSION_TAG}} +# ${{env.LASTEST_TAG}} + + # - name: Auto Execute a Workflow + # run: | + # echo "URL: http://10.10.11.26:8090/api/v1/repos/${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}/actions/workflows/CD.yml/dispatches" + # curl -X 'POST' \ + # 'http://10.10.11.26:8090/api/v1/repos/${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}/actions/workflows/CD.yml/dispatches' \ + # -H 'Accept: application/json' \ + # -H 'Content-Type: application/json' \ + # -H 'Authorization: Basic ${{ secrets.AUTH_BASIC }}' \ + # -H 'Authorization: token ${{ secrets.GHA_TOKEN }}' \ + # -d '{"ref":"${{ github.ref }}","inputs":{"version":"${{ steps.version_step.outputs.COMMIT_SHA_SHORT }}","env":"${{ github.ref_name}}"}}' + # shell: bash + # with: + # debug: true + +# - name: Auto Deploy (Dev) +## if: ${{ contains(github.ref, 'develop') and env.AUTO_DEPLOY_DEV == 'true' }} +# id: auto-deploy-dev +# uses: https://git.savin.nyc/gh-actions/auto-exec-workflow@v1 +# with: +# GITEA_TOKEN: ${{ secrets.GHA_TOKEN }} +# Version: ${{ steps.version.output.updated-version }} + + - name: Output Summary + id: output-summary + shell: bash + run: | + echo "CI pipeline has been compiled for ${{ github.repository }} with a new version ${{ steps.vars.outputs.COMMIT_SHORT_SHA }}" >> $GITHUB_STEP_SUMMARY \ No newline at end of file