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 }}