Skip to content

Commit

Permalink
chore: add publish docker image action
Browse files Browse the repository at this point in the history
  • Loading branch information
notaphplover committed Aug 9, 2024
1 parent 4bf81f9 commit eed5de1
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/actions/publish-docker-image/action.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
39 changes: 39 additions & 0 deletions .github/workflows/publish-docker-image.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit eed5de1

Please sign in to comment.