diff --git a/.github/actions/publish-docker-image/action.yaml b/.github/actions/publish-docker-image/action.yaml new file mode 100644 index 000000000..1630e9a76 --- /dev/null +++ b/.github/actions/publish-docker-image/action.yaml @@ -0,0 +1,49 @@ +name: Publish Docker image +description: Reusable action to build and push docker images + +inputs: + docker-image: + description: 'Docker image name' + required: true + docker-password: + description: 'Docker hub password' + required: true + docker-username: + description: 'Docker hub username' + required: true + npm-build-script: + description: 'npm build script to be called' + required: true + +runs: + using: "composite" + steps: + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - uses: pnpm/action-setup@v3 + name: Install pnpm + id: pnpm-install + with: + version: 9 + run_install: false + + - name: build docker image + run: pnpm run $NPM_SCRIPT + shell: bash + env: + NPM_SCRIPT: ${{ inputs.npm-build-script }} + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ inputs.docker-username }} + password: ${{ inputs.docker-password }} + + - name: push docker image + run: docker push $DOCKER_IMAGE --all-tags + shell: bash + env: + DOCKER_IMAGE: ${{ inputs.docker-image }} \ No newline at end of file diff --git a/.github/workflows/publish-docker-image.yaml b/.github/workflows/publish-docker-image.yaml new file mode 100644 index 000000000..184ce0620 --- /dev/null +++ b/.github/workflows/publish-docker-image.yaml @@ -0,0 +1,39 @@ +name: publish-docker-service-user-image +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +on: + workflow_dispatch: + inputs: + image: + type: choice + description: Docker image to be published + options: + - Game consumer + - Game service + - User service +jobs: + publish: + env: + DOCKER_IMAGE: > + ${{ fromJson('{ + "Game consumer": "robertopintosl/one-game-backend-consumer-game", + "Game service": "robertopintosl/one-game-backend-service-game", + "User service": "robertopintosl/one-game-backend-service-user" + }')[github.event.inputs.environment] }} + NPM_BUILD_SCRIPT: > + ${{ fromJson('{ + "Game consumer": "docker:build:game:consumer:npm", + "Game service": "docker:build:game:service:npm", + "User service": "docker:build:user:service:npm" + }')[github.event.inputs.environment] }} + name: Build and publish image + runs-on: ubuntu-latest + steps: + + - uses: ./.github/actions/publish-docker-image + with: + docker-image: ${{ env.DOCKER_IMAGE }} + docker-password: ${{ secrets.DOCKER_TOKEN }} + docker-username: ${{ vars.DOCKER_USERNAME }} + npm-build-script: ${{ env.NPM_BUILD_SCRIPT }} diff --git a/docker/backend/Dockerfile b/docker/backend/Dockerfile index 8309eb1cd..2fe6cc63f 100644 --- a/docker/backend/Dockerfile +++ b/docker/backend/Dockerfile @@ -63,3 +63,15 @@ COPY --from=backendservicegatewaybuild /prod/backend-service-gateway /prod/backe WORKDIR /prod/backend-service-gateway EXPOSE 3003 CMD [ "pnpm", "serve" ] + +FROM base AS npmbackendconsumergame +RUN pnpm i -g --prod @cornie-js/backend-consumer-game@0.3.0 +CMD [ "cornie-js-game-consumer-bootstrap" ] + +FROM base AS npmbackendservicegame +RUN pnpm i -g --prod @cornie-js/backend-service-game@0.3.0 +CMD [ "cornie-js-game-service-bootstrap" ] + +FROM base AS npmbackendserviceuser +RUN pnpm i -g --prod @cornie-js/backend-service-user@0.3.0 +CMD [ "cornie-js-user-service-bootstrap" ] diff --git a/package.json b/package.json index d3b12b60c..7b53d06c3 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,10 @@ "commit": "commit", "docker:build:game": "docker build . -f ./docker/backend/Dockerfile --target backendservicegame --tag robertopintosl/one-game-backend-service-game:latest", "docker:build:game:consumer": "docker build . -f ./docker/backend/Dockerfile --target backendconsumergame --tag robertopintosl/one-game-backend-consumer-game:latest", + "docker:build:game:consumer:npm": "docker build . -f ./docker/backend/Dockerfile --target npmbackendconsumergame --tag robertopintosl/one-game-backend-consumer-game:0.3.0 --tag robertopintosl/one-game-backend-consumer-game:0.3 --tag robertopintosl/one-game-backend-consumer-game:0 --tag robertopintosl/one-game-backend-consumer-game:latest", + "docker:build:game:service:npm": "docker build . -f ./docker/backend/Dockerfile --target npmbackendconsumergame --tag robertopintosl/one-game-backend-service-game:0.3.0 --tag robertopintosl/one-game-backend-service-game:0.3 --tag robertopintosl/one-game-backend-service-game:0 --tag robertopintosl/one-game-backend-service-game:latest", "docker:build:user": "docker build . -f ./docker/backend/Dockerfile --target backendserviceuser --tag robertopintosl/one-game-backend-service-user:latest", + "docker:build:user:service:npm": "docker build . -f ./docker/backend/Dockerfile --target npmbackendserviceuser --tag robertopintosl/one-game-backend-service-user:0.3.0 --tag robertopintosl/one-game-backend-service-user:0.3 --tag robertopintosl/one-game-backend-service-user:0 --tag robertopintosl/one-game-backend-service-user:latest", "docker:build:web-ui": "docker build . -f ./docker/frontend/Dockerfile --target frontendservicewebui --tag robertopintosl/one-game-frontend-service-web-ui:latest", "format": "turbo run format", "lint": "turbo run lint",