From 4a7f057169b62f79092f476072e7acc545b45a53 Mon Sep 17 00:00:00 2001 From: Sean Macfarlane Date: Fri, 17 Apr 2020 11:27:34 -0400 Subject: [PATCH] update docker --- .github/workflows/dockerimage.yml | 16 ------ .github/workflows/dockerpublish.yml | 76 +++++++++++++++++++++++++++++ Dockerfile | 4 +- docker-compose.test.yml | 3 ++ package.json | 1 + 5 files changed, 82 insertions(+), 18 deletions(-) delete mode 100644 .github/workflows/dockerimage.yml create mode 100644 .github/workflows/dockerpublish.yml create mode 100644 docker-compose.test.yml diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml deleted file mode 100644 index 3e83e27..0000000 --- a/.github/workflows/dockerimage.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: [ master ] - -jobs: - - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag wlan-cloud-graphql-gw:$(date +%s) diff --git a/.github/workflows/dockerpublish.yml b/.github/workflows/dockerpublish.yml new file mode 100644 index 0000000..d496c3f --- /dev/null +++ b/.github/workflows/dockerpublish.yml @@ -0,0 +1,76 @@ +name: Docker Publish + +on: + push: + # Publish `master` as Docker `latest` image. + branches: + - master + + # Publish `v1.2.3` tags as releases. + tags: + - v* + + # Run tests for any PRs. + pull_request: + +env: + IMAGE_NAME: wlan-cloud-graphql-gw + +jobs: + # Run tests. + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Run tests + run: | + if [ -f docker-compose.test.yml ]; then + docker-compose --file docker-compose.test.yml build + docker-compose --file docker-compose.test.yml run sut + else + docker build . --file Dockerfile + fi + push: + # Ensure test job passes before pushing image. + needs: test + + runs-on: ubuntu-latest + if: github.event_name == 'push' + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: docker build . --file Dockerfile --tag image + + - name: Login to TIP Docker registry + uses: azure/docker-login@v1 + with: + login-server: tip-tip-wlan-cloud-docker-repo.jfrog.io + username: build-pipeline + password: ${{ secrets.REPO_PASSWORD }} + + - name: Push image + run: | + IMAGE_ID=${{ github.repository }}/$IMAGE_NAME + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + # Use Docker `latest` tag convention + [ "$VERSION" == "master" ] && VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker tag image $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION diff --git a/Dockerfile b/Dockerfile index d3aabf2..d295fa6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,10 +10,10 @@ COPY package*.json ./ #RUN npm install # If you are building your code for production -RUN npm ci --only=production +RUN npm install # Bundle app source COPY . . EXPOSE 4000 -CMD [ "npm", "start" ] \ No newline at end of file +CMD [ "npm", "run", "prod" ] \ No newline at end of file diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..ec76a60 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,3 @@ +sut: + build: . + command: npm test \ No newline at end of file diff --git a/package.json b/package.json index 293d4ca..9d4fd09 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ }, "scripts": { "start": "NODE_ENV=development node -r esm src/index.js", + "prod": "node -r esm src/index.js", "test": "echo \"Error: no test specified\" && exit 1", "format": "prettier --write \"src/**/*.js\"", "eslint-fix": "eslint --fix . --ext .js --ext .gql --ext .graphql --max-warnings=0"