diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 01c9372..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,87 +0,0 @@ -version: 2 -jobs: - build_test_deploy: - machine: true - steps: - - checkout - - - run: - name: Build docker container - command: docker build -t "racemap/elevation-service:${CIRCLE_BUILD_NUM}" . - - - run: - name: Run unit tests - command: | - docker run \ - --rm \ - "racemap/elevation-service:${CIRCLE_BUILD_NUM}" \ - yarn test - - - run: - name: Run S3 tests - command: | - docker run \ - --rm \ - -d \ - -eTILE_SET_PATH=s3:// \ - -p3000:3000 \ - --name elevation \ - "racemap/elevation-service:${CIRCLE_BUILD_NUM}" - sleep 5 - RESULT=$(curl \ - -d '[[51.3, 13.4], [51.4, 13.3]]' \ - -XPOST \ - -H 'Content-Type: application/json' \ - http://localhost:3000) - [ "$RESULT" = "[101,100]" ] - RESULT=$(curl http://localhost:3000/\?lat\=51.3\&lng\=13.4) - [ "$RESULT" = "101" ] - docker stop elevation - - - run: - name: Run local tests - command: | - mkdir -p data/N51 - wget \ - http://elevation-tiles-prod.s3.amazonaws.com/skadi/N51/N51E013.hgt.gz \ - -O data/N51/N51E013.hgt.gz - docker run \ - --rm \ - -d \ - -p3000:3000 \ - --name elevation \ - -v$(pwd)/data:/app/data \ - "racemap/elevation-service:${CIRCLE_BUILD_NUM}" - sleep 5 - RESULT=$(curl \ - -d '[[51.3, 13.4], [51.4, 13.3]]' \ - -XPOST \ - -H 'Content-Type: application/json' \ - http://localhost:3000) - [ "$RESULT" = "[101,100]" ] - RESULT=$(curl http://localhost:3000/\?lat\=51.3\&lng\=13.4) - [ "$RESULT" = "101" ] - docker stop elevation - - - run: - name: Push Docker images - command: | - echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin - docker tag \ - "racemap/elevation-service:${CIRCLE_BUILD_NUM}" \ - "racemap/elevation-service:${CIRCLE_BRANCH}" - docker push "racemap/elevation-service:${CIRCLE_BUILD_NUM}" - docker push "racemap/elevation-service:${CIRCLE_BRANCH}" - if [ "${CIRCLE_BRANCH}" == "master" ]; then - docker tag \ - "racemap/elevation-service:${CIRCLE_BUILD_NUM}" \ - "racemap/elevation-service:latest" - docker push "racemap/elevation-service:latest" - fi - docker logout - -workflows: - version: 2 - default: - jobs: - - build_test_deploy diff --git a/.github/workflows/buildImage.yml b/.github/workflows/buildImage.yml new file mode 100644 index 0000000..448bd6b --- /dev/null +++ b/.github/workflows/buildImage.yml @@ -0,0 +1,93 @@ +name: Build Image + +on: + push: + branches: + - 'master' + tags: + - 'v*' + pull_request: + branches: + - 'master' + +jobs: + image: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: racemap/elevation-service + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + + - name: Build + uses: docker/build-push-action@v4 + with: + push: false + load: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Test S3 + run: | + docker run \ + --rm \ + -d \ + -eTILE_SET_PATH=s3:// \ + -p3000:3000 \ + --name elevation \ + "racemap/elevation-service:${{ steps.meta.outputs.version }}" + sleep 5 + RESULT=$(curl \ + -d '[[51.3, 13.4], [51.4, 13.3]]' \ + -XPOST \ + -H 'Content-Type: application/json' \ + http://localhost:3000) + [ "$RESULT" = "[101,100]" ] + RESULT=$(curl http://localhost:3000/\?lat\=51.3\&lng\=13.4) + [ "$RESULT" = "101" ] + docker stop elevation + + - name: Test Local + run: | + mkdir -p data/N51 + wget \ + https://elevation-tiles-prod.s3.amazonaws.com/skadi/N51/N51E013.hgt.gz \ + -O data/N51/N51E013.hgt.gz + docker run \ + --rm \ + -d \ + -p3000:3000 \ + --name elevation \ + -v$(pwd)/data:/app/data \ + "racemap/elevation-service:${{ steps.meta.outputs.version }}" + sleep 5 + RESULT=$(curl \ + -d '[[51.3, 13.4], [51.4, 13.3]]' \ + -XPOST \ + -H 'Content-Type: application/json' \ + http://localhost:3000) + [ "$RESULT" = "[101,100]" ] + RESULT=$(curl http://localhost:3000/\?lat\=51.3\&lng\=13.4) + [ "$RESULT" = "101" ] + docker stop elevation + + - name: Push + uses: docker/build-push-action@v4 + if: github.event_name != 'pull_request' + with: + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index a279c0f..bb3395d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM node:14 COPY . /app WORKDIR /app -RUN yarn install +RUN yarn install --frozen-lockfile && yarn test ENV TILE_SET_CACHE 128 ENV TILE_SET_PATH /app/data @@ -12,4 +12,4 @@ EXPOSE 3000 HEALTHCHECK CMD curl --fail http://localhost:3000/status || exit 1 -CMD ["yarn", "run", "start"] +CMD ["yarn", "start"] diff --git a/index.js b/index.js index e448921..83d9fc2 100644 --- a/index.js +++ b/index.js @@ -58,7 +58,15 @@ async function handleGET(req, res) { } async function handleGETStatus(req, res) { - return send(res, 200, 'Ok'); + try { + // try to receive a test value + await tiles.getElevation([0, 0]); + return send(res, 200, 'Ok'); + } catch (error) { + console.error('Status Check Failed!'); + console.error(error); + return send(res, 500, 'Error'); + } } async function handler(req, res) {