Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mijailr committed Jan 23, 2024
1 parent a5eaf2f commit 61adac2
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 15 deletions.
75 changes: 64 additions & 11 deletions .github/actions/publish-image/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Build and publish docker images
description: Builds and publish docker images to github registry
inputs:
github-token:
description: Github secret secrets.GITHUB_TOKEN
required: true
image-name:
description: Image name for example lh-server
required: true
Expand All @@ -13,29 +10,80 @@ inputs:
dockerfile:
description: Relative route of Dockerfile
required: true
registry:
description: Either github or ecr
default: github
github-token:
description: Github secret secrets.GITHUB_TOKEN required only if registry is github
default: ""
prefix:
description: prefix to be appended to image tag ex brach-
default: ""

runs:
using: composite
steps:
- name: Registry not recognized
shell: bash
if: ${{ inputs.registry != 'github' && inputs.registry != 'ecr' }}
run: |
echo "Registry not recognized, it should be github or ecr"
exit 1
- name: github-token is required
shell: bash
if: ${{ inputs.registry == 'github' && inputs.github-token == '' }}
run: |
echo "github-token is required when registry is github"
exit 1
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to github registry
if: ${{ inputs.registry == 'github'}}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ inputs.github-token }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Configure AWS credentials
if: ${{ inputs.registry == 'ecr' }}
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::637423582379:role/GithubActions-ECR
role-session-name: gha-ecr
aws-region: us-west-2

- name: Login to Amazon ECR
id: login-ecr
if: ${{ inputs.registry == 'ecr' }}
uses: aws-actions/amazon-ecr-login@v2

- name: Set DOCKER_IMAGE to github
if: ${{ inputs.registry == 'github'}}
shell: bash
run: |
echo DOCKER_IMAGE=ghcr.io/${{ github.repository }}/${{ inputs.image-name }} >> $GITHUB_ENV
- name: Set DOCKER_IMAGE to ecr
if: ${{ inputs.registry == 'ecr' }}
shell: bash
run: |
echo DOCKER_IMAGE=${{ steps.login-ecr.outputs.registry }}/${{ inputs.image-name }} >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
id: meta
with:
images: |
ghcr.io/${{ github.repository }}/${{ inputs.image-name }}
${{ env.DOCKER_IMAGE }}
flavor: |
prefix=${{ inputs.prefix }}
- name: Build and push Docker images
uses: docker/build-push-action@v5
Expand All @@ -45,3 +93,8 @@ runs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Annotate image
shell: bash
run: |
echo "::notice title=Published Docker Image::${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.tags }}"
52 changes: 52 additions & 0 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: branch
run-name: Publishing images for branch ${{ github.ref_name }}
on:
push:
branches-ignore:
- "master"
permissions:
id-token: write
contents: read
jobs:
lh-server:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: "corretto"
java-version: 17

- name: Tests and Build
run: ./gradlew server:test server:shadowJar

- name: Build and publish
uses: ./.github/actions/publish-image
with:
image-name: lh-server
dockerfile: docker/server/Dockerfile
registry: ecr
prefix: branch-

lh-dashboard:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build Dashboard
working-directory: ./dashboard
run: |
npm install pnpm --global
pnpm install
pnpm build
- name: Build and publish
uses: ./.github/actions/publish-image
with:
image-name: lh-dashboard
dockerfile: docker/dashboard/Dockerfile
registry: ecr
prefix: branch-
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: publish
run-name: Publish
name: release
run-name: Release ${{ github.ref_name }}
on:
push:
tags:
Expand All @@ -14,7 +14,7 @@ jobs:
sdk-java:
runs-on: ubuntu-latest
needs:
- build-server
- publish-docker
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
sdk-python:
runs-on: ubuntu-latest
needs:
- build-server
- publish-docker
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down

0 comments on commit 61adac2

Please sign in to comment.