From 5937d3026a272c7e999fbb9b558f496dc62df9aa Mon Sep 17 00:00:00 2001 From: Ashwini Sukale Date: Sat, 16 Dec 2023 13:40:53 +0530 Subject: [PATCH 1/5] Add gitworkflow on pull request --- .github/workflows/build.yml | 149 ++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1b18b12 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,149 @@ +name: Build +on: + pull_request: + branches: + - "master" +jobs: + test: + runs-on: ubuntu-latest + services: + memcached: + image: memcached:1.4.31 + ports: + - 11211/udp + env: + MEMCACHE_SERVERS: "localhost:11211" + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby 2.6 + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - uses: actions/cache@v3 + with: + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems- + - name: Install + env: + MYSQL_PORT: ${{ job.services.mysql.ports[3306] }} + run: | + cp .env.build .env + gem install bundler + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + - name: Lint and Test + env: + MEMCACHE_SERVERS: "localhost:11211" + run: | + # Run the tests in subsets instead of all at once. + bundle exec rspec spec + + build: + needs: test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Push to Docker Hub + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ github.repository }}:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + - name: Push to GitHub Packages + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: ghcr.io/${{ github.repository }}:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + deploy: + needs: [test, build] + runs-on: ubuntu-latest + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Extract variables + shell: bash + run: | + echo "::set-output name=BRANCH::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" + echo "::set-output name=TAG::$(git tag --points-at HEAD)" + echo "::set-output name=GIT_SHA::$(git rev-parse HEAD)" + echo "::set-output name=GIT_SHA_SHORT::$(git rev-parse --short HEAD)" + echo "::set-output name=MESSAGE::$(git log --format=%B -n 1 ${{ github.event.after }})" + id: extract_variables + + - name: Checkout terraform config repo + uses: actions/checkout@v3 + with: + # public repo with terraform configuration + repository: 'datacite/mastino' + persist-credentials: false + - name: Commit changes to terraform config repository + # use go template in terraform config repository to update git sha and tag + # commit and push changes to trigger terraform workflow + run: | + export GIT_SHA=${{ steps.extract_variables.outputs.GIT_SHA_SHORT }} + export GIT_TAG=${{ steps.extract_variables.outputs.GIT_TAG }} + wget https://github.com/jwilder/dockerize/releases/download/v0.6.0/dockerize-linux-amd64-v0.6.0.tar.gz + tar -xzvf dockerize-linux-amd64-v0.6.0.tar.gz + rm dockerize-linux-amd64-v0.6.0.tar.gz + ./dockerize -template stage/services/content-negotiation/_content-negotiation.auto.tfvars.tmpl:stage/services/content-negotiation/_content-negotiation.auto.tfvars + + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add stage/services/content-negotiation/_content-negotiation.auto.tfvars + git commit -m "Adding content-negotiation git variables for commit ${{ steps.extract_variables.outputs.GIT_SHA }}" + - name: Push changes + uses: ad-m/github-push-action@v0.6.0 + with: + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + repository: 'datacite/mastino' + branch: 'refs/heads/master' + tags: false + + # - name: Notify Slack + # uses: edge/simple-slack-notify@master + # with: + # channel: '#ops' + # color: 'good' + # text: 'A new version of the is been deployed to stage.' + # failure_text: '${env.GITHUB_WORKFLOW} (${env.GITHUB_RUN_NUMBER}) build failed' + # fields: | + # [{ "title": "Commit message", "value": "${{ steps.extract_variables.outputs.MESSAGE }}" }, + # { "title": "Committed by", "value": "", "short": true }, + # { "title": "Commit SHA", "value": "", "short": true }, + # { "title": "Repository", "value": "", "short": true }, + # { "title": "Branch", "value": "", "short": true }] From e2ca1c5db479818984e78242f4d7539091b25efc Mon Sep 17 00:00:00 2001 From: Ashwini Sukale Date: Sat, 16 Dec 2023 13:43:56 +0530 Subject: [PATCH 2/5] Added ruby 2.6 compatible bundler version --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b18b12..7003db7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,7 +30,7 @@ jobs: MYSQL_PORT: ${{ job.services.mysql.ports[3306] }} run: | cp .env.build .env - gem install bundler + gem install bundler -v 2.1.4 bundle config path vendor/bundle bundle install --jobs 4 --retry 3 - name: Lint and Test From b8d1bc92464fabf374fcc676ac98431311f5a375 Mon Sep 17 00:00:00 2001 From: Ashwini Sukale Date: Sat, 16 Dec 2023 13:49:34 +0530 Subject: [PATCH 3/5] Fixed dockerfile to use proper bundler version as per ruby 2.6 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6264715..2ce2d2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,7 @@ RUN mkdir -p vendor/bundle && \ chown -R app:app . && \ chmod -R 755 . && \ gem update --system && \ - gem install bundler && \ + gem install bundler -v 2.1.4 && \ /sbin/setuser app bundle install --path vendor/bundle # Copy webapp folder From d951b1b486e151f9b12e088856f4ff3595007a49 Mon Sep 17 00:00:00 2001 From: Ashwini Sukale Date: Sat, 16 Dec 2023 13:59:56 +0530 Subject: [PATCH 4/5] Update the gem version as per ruby 2.6 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2ce2d2e..fc2da0b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,7 @@ WORKDIR /home/app/webapp RUN mkdir -p vendor/bundle && \ chown -R app:app . && \ chmod -R 755 . && \ - gem update --system && \ + gem update --system -v 3.0.8 && \ gem install bundler -v 2.1.4 && \ /sbin/setuser app bundle install --path vendor/bundle From 67af2e27380575e3e74bc1571100e414f1fbbf62 Mon Sep 17 00:00:00 2001 From: Ashwini Sukale Date: Sat, 16 Dec 2023 14:06:23 +0530 Subject: [PATCH 5/5] fixed syntax --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fc2da0b..4097c74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,7 @@ WORKDIR /home/app/webapp RUN mkdir -p vendor/bundle && \ chown -R app:app . && \ chmod -R 755 . && \ - gem update --system -v 3.0.8 && \ + gem update --system 3.0.8 && \ gem install bundler -v 2.1.4 && \ /sbin/setuser app bundle install --path vendor/bundle