From 57c661603c685a264db80f791002e93ea0763ec1 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Tue, 21 Dec 2021 16:10:47 -0500 Subject: [PATCH] Replacing Circle CI with GH actions - Building and pushing images to our artifactory --- .circleci/config.yml | 62 ---------------------- .github/workflows/docker_build_push.yaml | 66 ++++++++++++++++++++++++ Dockerfile | 5 +- 3 files changed, 69 insertions(+), 64 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/docker_build_push.yaml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 0f2fc45..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,62 +0,0 @@ -shared_configs: - simple_job_steps: &simple_job_steps - - checkout - - run: - name: Run tests - command: | - make deps test - - -# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference -version: 2.1 -jobs: - build-1-14: - working_directory: ~/repo - docker: - - image: circleci/golang:1.14 - steps: *simple_job_steps - - build-1-15: - working_directory: ~/repo - docker: - - image: circleci/golang:1.15 - steps: *simple_job_steps - - build-1-16: - working_directory: ~/repo - docker: - - image: circleci/golang:1.16 - steps: - - checkout - - restore_cache: - keys: - - go-mod-v4-{{ checksum "go.sum" }} - - run: - name: Install Dependencies - command: go mod download - - save_cache: - key: go-mod-v4-{{ checksum "go.sum" }} - paths: - - "/go/pkg/mod" - - run: - name: Run tests - command: | - #mkdir -p /tmp/test-reports - #gotestsum --junitfile /tmp/test-reports/unit-tests.xml - make ci - #- store_test_results: - # path: /tmp/test-reports - - build-1-17: - working_directory: ~/repo - docker: - - image: circleci/golang:1.17 - steps: *simple_job_steps - -workflows: - pr-build-test: - jobs: - - build-1-14 - - build-1-15 - - build-1-16 - - build-1-17 diff --git a/.github/workflows/docker_build_push.yaml b/.github/workflows/docker_build_push.yaml new file mode 100644 index 0000000..0aa3800 --- /dev/null +++ b/.github/workflows/docker_build_push.yaml @@ -0,0 +1,66 @@ +--- +on: + push: + branches: + - '**' # matches every branch + tags: + - '*' # matches every tag that doesn't contain a '/' + +jobs: + build_and_push_image: + # runs-on: ubuntu-latest + runs-on: self-hosted + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Prepare + id: prep + run: | + DOCKER_IMAGE=xmix-docker-dev/grpcurl + VERSION=edge + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/} + elif [[ $GITHUB_REF == refs/heads/* ]]; then + VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') + elif [[ $GITHUB_REF == refs/pull/* ]]; then + VERSION=pr-${{ github.event.number }} + fi + TAGS="${DOCKER_IMAGE}:${VERSION}" + # TODO: Refine... was creating too many hashes + # if [ "${{ github.event_name }}" = "push" ]; then + # TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" + # fi + # if we pushed a tag, we also want publish a new latest image + if [[ $GITHUB_REF == refs/tags/* ]]; then + TAGS="$TAGS,${DOCKER_IMAGE}:latest" + fi + echo "TAGS to build and push are ${TAGS}" + echo ::set-output name=version::${VERSION} + echo ::set-output name=tags::${TAGS} + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to Nuance JFrog Artifactory + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ${{ secrets.ARTIFACTORY_URL }} + username: ${{ secrets.XMIX_PUBLISH_USERNAME }} + password: ${{ secrets.XMIX_PUBLISH_PASSWORD }} + - + name: Build and push to artifactory + uses: docker/build-push-action@v2 + with: + build-args: VERSION=${{ steps.prep.outputs.version }} + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: "${{ secrets.ARTIFACTORY_URL }}/${{ steps.prep.outputs.tags }}" + labels: | + org.opencontainers.image.source=${{ github.event.repository.html_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index 29d1010..4b1fae8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ FROM golang:1.17.3-alpine as builder +ARG ${VERSION:-1.0.0} MAINTAINER FullStory Engineering # create non-privileged group and user @@ -6,14 +7,14 @@ RUN addgroup -S grpcurl && adduser -S grpcurl -G grpcurl WORKDIR /tmp/fullstorydev/grpcurl # copy just the files/sources we need to build grpcurl -COPY VERSION *.go go.* /tmp/fullstorydev/grpcurl/ +COPY *.go go.* /tmp/fullstorydev/grpcurl/ COPY cmd /tmp/fullstorydev/grpcurl/cmd # and build a completely static binary (so we can use # scratch as basis for the final image) ENV CGO_ENABLED=0 ENV GO111MODULE=on RUN go build -o /grpcurl \ - -ldflags "-w -extldflags \"-static\" -X \"main.version=$(cat VERSION)\"" \ + -ldflags "-w -extldflags \"-static\" -X \"main.version=${VERSION}\"" \ ./cmd/grpcurl # New FROM so we have a nice'n'tiny image