From 7b34eaa0b772fd4c58487bd09bbae1820413c48b Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 30 Dec 2023 11:59:20 +0000 Subject: [PATCH] Convert pipeline to GH Actions --- .github/workflows/build.yaml | 37 ++++++++++++++++++++++++++++++++++++ .travis.yml | 27 -------------------------- Dockerfile | 4 +--- README.md | 4 +--- 4 files changed, 39 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/build.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..5675b3c --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,37 @@ +name: Build docker image +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Export variables + run: echo "IMAGE_TAG=ghcr.io/micromaomao/schsrch" >> $GITHUB_ENV + - name: Build script + run: > + git clean -dfx && + chmod u=rwX,go=rX . -R && + docker build . -t $IMAGE_TAG --no-cache && + docker-compose -f docker-compose-example.yml up -d es mongo && + sleep 40 && + docker run --entrypoint=bash --user=www -t --network schsrch_mw -e NODE_ENV=development -e MONGODB=mongodb://mw-mongo/schsrch -e ES=mw-es:9200 -e SITE_ORIGIN=http://localhost -v $(pwd)/.git:/usr/src/app/.git $IMAGE_TAG -c "npm install coveralls && npm install istanbul && test/prepareDatabase.sh && npm run coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"; + if [ $? -ne 0 ]; then + exit 1; + fi; + docker run --entrypoint=bash -t --network schsrch_mw -p 3000:80 -e NODE_ENV=production -e MONGODB=mongodb://mw-mongo/schsrch -e ES=mw-es:9200 -e SITE_ORIGIN=http://localhost $IMAGE_TAG -c "node server.js" & + sleep 10 && + curl -vI 'http://127.0.0.1:3000' + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Push + run: > + docker push $IMAGE_TAG diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d0a7c2b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -sudo: no -dist: stretch -group: edge -language: generic -services: - - docker - -script: - - > - git clean -dfx && - chmod u=rwX,go=rX . -R && - docker build . -t maowtm/schsrch --no-cache && - docker-compose -f docker-compose-example.yml up -d es mongo && - sleep 40 && - docker run --entrypoint=bash --user=www -t --network schsrch_mw -e NODE_ENV=development -e MONGODB=mongodb://mw-mongo/schsrch -e ES=mw-es:9200 -e SITE_ORIGIN=http://localhost -e COVERALLS_REPO_TOKEN=$COVERALLS_REPO_TOKEN -v $(pwd)/.git:/usr/src/app/.git maowtm/schsrch -c "npm install coveralls && npm install istanbul && test/prepareDatabase.sh && npm run coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"; - if [ $? -ne 0 ]; then - exit 1; - fi; - docker run --entrypoint=bash -t --network schsrch_mw -p 3000:80 -e NODE_ENV=production -e MONGODB=mongodb://mw-mongo/schsrch -e ES=mw-es:9200 -e SITE_ORIGIN=http://localhost maowtm/schsrch -c "node server.js" & - sleep 10 && - curl -vI 'http://127.0.0.1:3000' - -deploy: - provider: script - script: echo "$DOCKERHUB_PASSWORD" | docker login -u "maowtm" --password-stdin && docker push maowtm/schsrch - on: - branch: master diff --git a/Dockerfile b/Dockerfile index 160ccde..6cb6270 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,10 +8,8 @@ RUN chown -R node:node /usr/src/app && \ setcap 'cap_net_bind_service=ep' /usr/local/bin/node USER node:node -COPY --chown=node:node ./package.json . -RUN npm i --progress=false --loglevel=warn 2>&1 COPY --chown=node:node . . -RUN npm i --progress=false --loglevel=warn 2>&1 +RUN npm ci EXPOSE 80 443 STOPSIGNAL SIGTERM HEALTHCHECK --timeout=2s CMD curl -f https://localhost/ diff --git a/README.md b/README.md index bcb1fdd..f336c41 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ ![demo video](readme_video.gif) -[![Build Status](https://travis-ci.org/micromaomao/schsrch.svg?branch=master)](https://travis-ci.org/micromaomao/schsrch) -[![Coverage Status](https://coveralls.io/repos/github/micromaomao/schsrch/badge.svg?branch=dev)](https://coveralls.io/github/micromaomao/schsrch?branch=dev) [![Dependencies](https://david-dm.org/micromaomao/schsrch.svg)](https://david-dm.org/micromaomao/schsrch) [![devDependencies Status](https://david-dm.org/micromaomao/schsrch/dev-status.svg)](https://david-dm.org/micromaomao/schsrch?type=dev) [![Known Vulnerabilities](https://snyk.io/test/github/micromaomao/schsrch/badge.svg)](https://snyk.io/test/github/micromaomao/schsrch) @@ -13,7 +11,7 @@ ## Ready-to-run docker image -[![](https://images.microbadger.com/badges/image/maowtm/schsrch.svg) maowtm/schsrch](https://hub.docker.com/r/maowtm/schsrch/) +[![](https://images.microbadger.com/badges/image/ghcr.io/micromaomao/schsrch.svg) ghcr.io/micromaomao/schsrch](ghcr.io/micromaomao/schsrch) Environment variables needed: (i.e. docker run -e xxx=xxx -e… maowtm/schsrch)