diff --git a/.github/actions/publish-image/action.yml b/.github/actions/publish-image/action.yml index f0dd00b4d7..98222d20d9 100644 --- a/.github/actions/publish-image/action.yml +++ b/.github/actions/publish-image/action.yml @@ -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 @@ -13,29 +10,74 @@ 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: "" 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 with: images: | - ghcr.io/${{ github.repository }}/${{ inputs.image-name }} + ${{ env.DOCKER_IMAGE }} - name: Build and push Docker images uses: docker/build-push-action@v5 diff --git a/.github/workflows/branch.yml b/.github/workflows/branch.yml new file mode 100644 index 0000000000..facb253436 --- /dev/null +++ b/.github/workflows/branch.yml @@ -0,0 +1,49 @@ +name: branch +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 + + 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 diff --git a/.github/workflows/publish.yml b/.github/workflows/release.yml similarity index 95% rename from .github/workflows/publish.yml rename to .github/workflows/release.yml index 3d2f6da389..f5c83f1b08 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,5 @@ -name: publish -run-name: Publish +name: release +run-name: Release ${{ github.ref_name }} on: push: tags: @@ -14,7 +14,7 @@ jobs: sdk-java: runs-on: ubuntu-latest needs: - - build-server + - publish-docker steps: - name: Checkout uses: actions/checkout@v3 @@ -42,7 +42,7 @@ jobs: sdk-python: runs-on: ubuntu-latest needs: - - build-server + - publish-docker steps: - name: Checkout uses: actions/checkout@v3