diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 70b9154..9c150e7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,8 +14,14 @@ on: inputs: version: default: v1.0.0 - description: Bump Version + description: Select environment + options: + - Dev + - Qa + - Stage + - Prod required: true + type: choice jobs: push_to_registry: @@ -38,14 +44,66 @@ jobs: username: ${{ secrets.CI_QUAY_USERNAME }} password: ${{ secrets.CI_QUAY_TOKEN }} - - name: Build and push into repository - id: docker_build + - name: Dev Build and push into repository + if: github.event.inputs.env == 'Dev' + id: docker_build_dev uses: docker/build-push-action@v2 with: context: . file: ./Dockerfile push: ${{ github.event_name != 'pull_request' }} + build-args: | + USERGROUP=${{ secrets.DEV_GIT_BROKER_USERGROUP }} tags: | - quay.io/${{ env.REGISTRY_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{env.GITHUB_REF_SLUG}} + quay.io/${{ env.REGISTRY_NAMESPACE }}/${{ env.IMAGE_NAME }}:dev-${{env.GITHUB_REF_SLUG}} - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} + run: echo ${{ steps.docker_build_dev.outputs.digest }} + + + - name: QA Build and push into repository + if: github.event.inputs.env == 'Qa' + id: docker_build_qa + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + build-args: | + USERGROUP=${{ secrets.QA_GIT_BROKER_USERGROUP }} + tags: | + quay.io/${{ env.REGISTRY_NAMESPACE }}/${{ env.IMAGE_NAME }}:qa-${{env.GITHUB_REF_SLUG}} + - name: Image digest + run: echo ${{ steps.docker_build_dev.outputs.digest }} + + + - name: Stage Build and push into repository + if: github.event.inputs.env == 'Stage' + id: docker_build_stage + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + build-args: | + USERGROUP=${{ secrets.STAGE_GIT_BROKER_USERGROUP }} + tags: | + quay.io/${{ env.REGISTRY_NAMESPACE }}/${{ env.IMAGE_NAME }}:stage-${{env.GITHUB_REF_SLUG}} + - name: Image digest + run: echo ${{ steps.docker_build_dev.outputs.digest }} + + + - name: Prod Build and push into repository + if: github.event.inputs.env == 'Prod' + id: docker_build_prod + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + build-args: | + USERGROUP=${{ secrets.PROD_GIT_BROKER_USERGROUP }} + tags: | + quay.io/${{ env.REGISTRY_NAMESPACE }}/${{ env.IMAGE_NAME }}:prod-${{env.GITHUB_REF_SLUG}} + - name: Image digest + run: echo ${{ steps.docker_build_dev.outputs.digest }} + diff --git a/Dockerfile b/Dockerfile index 47c7c1a..afed6ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,24 @@ FROM node:18-alpine3.16 AS build -RUN addgroup -S puzzgroup && adduser -S -G puzzgroup puzzuser +ARG USERGROUP + +RUN addgroup allusers && adduser -S -G allusers $USERGROUP +RUN mkdir /.npm +RUN mkdir /.npm/_cacache + WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . -RUN chown -R puzzuser:puzzgroup /app -USER puzzuser +RUN chown -R $USERGROUP:allusers . +RUN chown -R $USERGROUP:allusers ~/.npm +RUN chown -R $USERGROUP:allusers /.npm +RUN chmod -R 777 . EXPOSE 9191 +USER $USERGROUP + CMD ["npm", "run", "start"] \ No newline at end of file