From f3bd66a29ed0303e8300520060b43e8556cc8d62 Mon Sep 17 00:00:00 2001 From: Evening Date: Mon, 1 Apr 2024 22:40:15 +0800 Subject: [PATCH] Create docker build --- .github/workflows/build-ls-image.yml | 44 ++++++++++++++++++++++++++++ src/terraform/Dockerfile | 36 +++++++++++++++-------- 2 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/build-ls-image.yml diff --git a/.github/workflows/build-ls-image.yml b/.github/workflows/build-ls-image.yml new file mode 100644 index 00000000..64e9c725 --- /dev/null +++ b/.github/workflows/build-ls-image.yml @@ -0,0 +1,44 @@ +name: Create and publish our custom Label Studio Docker image +on: + push: + branches: [ 'terraform' ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3.1.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + uses: docker/build-push-action@v5.3.0 + with: + context: ./src/terraform + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/src/terraform/Dockerfile b/src/terraform/Dockerfile index 78548a65..978a1fab 100644 --- a/src/terraform/Dockerfile +++ b/src/terraform/Dockerfile @@ -10,20 +10,30 @@ RUN pip3 install label-studio # to the host machine. You need to do that manually EXPOSE 8080 -ARG POSTGRE_PASSWORD -ARG POSTGRE_USER -ARG POSTGRE_HOST - -# Assert that the POSTGRE_PASSWORD and POSTGRE_USER -RUN test -n "$POSTGRE_PASSWORD" || (echo "POSTGRE_PASSWORD is not set" && exit 1) -RUN test -n "$POSTGRE_USER" || (echo "POSTGRE_USER is not set" && exit 1) -RUN test -n "$POSTGRE_HOST" || (echo "POSTGRE_HOST is not set" && exit 1) - ENV DJANGO_DB=default ENV POSTGRE_NAME=postgres ENV POSTGRE_PORT=5432 -ENV POSTGRE_PASSWORD=$POSTGRE_PASSWORD -ENV POSTGRE_USER=$POSTGRE_USER -ENV POSTGRE_HOST=$POSTGRE_HOST -CMD ["label-studio"] +ENTRYPOINT ["label-studio"] + +# This is deprecated code that is no longer needed +# This is used if you are building a static image with predefined +# Postgres credentials, however it's best if we run the image with environment +# variables passed in from the host machine +# +# E.g. +# docker run image_tag \ +# -e POSTGRE_PASSWORD=pass +# -e POSTGRE_USER=user +# -e POSTGRE_HOST=host +#ARG POSTGRE_PASSWORD +#ARG POSTGRE_USER +#ARG POSTGRE_HOST +# +## Assert that the POSTGRE_PASSWORD and POSTGRE_USER +#RUN test -n "$POSTGRE_PASSWORD" || (echo "POSTGRE_PASSWORD is not set" && exit 1) +#RUN test -n "$POSTGRE_USER" || (echo "POSTGRE_USER is not set" && exit 1) +#RUN test -n "$POSTGRE_HOST" || (echo "POSTGRE_HOST is not set" && exit 1) +#ENV POSTGRE_PASSWORD=$POSTGRE_PASSWORD +#ENV POSTGRE_USER=$POSTGRE_USER +#ENV POSTGRE_HOST=$POSTGRE_HOST