diff --git a/.dockerignore b/.dockerignore index 72e8ffc..c2c6dd5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,4 @@ * +!*.js +!*.json +!/bin diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a1cf714 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,47 @@ +name: 'Build and push' + +on: + push: + branches: + - master + tags: + - '*' + +jobs: + build: + runs-on: ubuntu-22.04 + steps: + - name: 'Checkout code' + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: 'Set image tag and name' + id: tag + run: | + IMAGE_TAG="master" + if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then + REF=${{ github.ref }}; + TAG_FULL=${REF#refs/*/}; + IMAGE_TAG=${TAG_FULL//\//_}; + fi + echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT + echo "image_name=${{ secrets.IMAGE_NAME }}" >> $GITHUB_OUTPUT + + - name: 'Login to Docker Hub' + uses: docker/login-action@v2 + with: + username: ${{ secrets.REGISTRY_LOGIN }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: 'Set up Docker Buildx' + uses: docker/setup-buildx-action@v2 + + - name: 'Build and push' + id: docker_build + uses: docker/build-push-action@v4 + with: + push: true + tags: ${{steps.tag.outputs.image_name}}:${{steps.tag.outputs.image_tag}} + cache-from: type=registry,ref=${{ steps.tag.outputs.image_name }}:buildcache + cache-to: type=registry,ref=${{ steps.tag.outputs.image_name }}:buildcache,mode=max diff --git a/Dockerfile b/Dockerfile index 6e8b874..9d8ef12 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM node:14-alpine -ARG ReviewMeVersion=2 +ADD . /app/ +WORKDIR /app -# Workaroudn when building on an AWS EC2 c5/m5/t3 instance -# RUN npm config set unsafe-perm true +RUN npm install -g . -RUN npm install -g @trademe/reviewme@${ReviewMeVersion} +CMD reviewme diff --git a/reviews.js b/reviews.js index bf8420f..3acf146 100644 --- a/reviews.js +++ b/reviews.js @@ -2,6 +2,7 @@ const request = require('request'); const appstore = require('./appstorereviews.js'); const googlePlay = require('./googleplayreviews.js'); const fs = require('fs'); +const dataDir = "/var/lib/reviewme"; const REVIEWS_STORES = { "APP_STORE": "app-store", @@ -10,13 +11,17 @@ const REVIEWS_STORES = { var published_reviews; try { - published_reviews = JSON.parse(fs.readFileSync('./published_reviews.json')); + published_reviews = JSON.parse(fs.readFileSync(dataDir + '/published_reviews.json')); } catch (err) { published_reviews = {} } (function () { exports.start = function start(config) { + if (!fs.existsSync(dataDir)) { + fs.mkdirSync(dataDir, { recursive: true }); + } + if (!config.store) { // Determine from which store reviews are downloaded config.store = (config.appId.indexOf("\.") > -1) ? REVIEWS_STORES.GOOGLE_PLAY : REVIEWS_STORES.APP_STORE; @@ -52,7 +57,7 @@ exports.markReviewAsPublished = function (config, review) { console.log("INFO: Review marked as published: " + JSON.stringify(published_reviews[config.appId])); } - fs.writeFileSync('./published_reviews.json', JSON.stringify(published_reviews), { flag: 'w' }) + fs.writeFileSync(dataDir + '/published_reviews.json', JSON.stringify(published_reviews), { flag: 'w' }) }; exports.reviewPublished = function (config, review) {