From 8be0ce82f69b6bc0d5a7f06d9ed3eb7e3f9e38a5 Mon Sep 17 00:00:00 2001 From: Mathias Beaulieu-Duncan Date: Mon, 30 Dec 2024 14:16:51 -0500 Subject: [PATCH] added DB_NAME env variable and added gitea workflow to publish the container --- .gitea/workflows/publish-containers.yaml | 49 ++++++++++++++++++++++++ 18.0/entrypoint.sh | 2 + 18.0/wait-for-psql.py | 3 +- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/publish-containers.yaml diff --git a/.gitea/workflows/publish-containers.yaml b/.gitea/workflows/publish-containers.yaml new file mode 100644 index 0000000..0175edb --- /dev/null +++ b/.gitea/workflows/publish-containers.yaml @@ -0,0 +1,49 @@ +name: Build, Secure, and Push Docker Image on Release + +on: + release: + types: [published, prereleased] + +permissions: + id-token: write + contents: read + packages: write + +env: + DOCKER_IMAGE_NAME: docker.io/openharbor/odoo + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} + + - name: Determine Tag Type + id: tag_type + run: | + if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then + echo "tag=dev" >> $GITHUB_ENV + else + echo "tag=latest" >> $GITHUB_ENV + fi + + - name: Build, push, and generate SBOM and provenance + run: | + docker buildx build \ + --provenance=true \ + --sbom=true \ + --push \ + -t ${{ env.DOCKER_IMAGE_NAME }}:${{ github.event.release.tag_name }} \ + -t ${{ env.DOCKER_IMAGE_NAME }}:${{ env.tag }} \ + . \ No newline at end of file diff --git a/18.0/entrypoint.sh b/18.0/entrypoint.sh index f802bcb..a208e2c 100755 --- a/18.0/entrypoint.sh +++ b/18.0/entrypoint.sh @@ -12,6 +12,7 @@ fi : ${PORT:=${DB_PORT_5432_TCP_PORT:=5432}} : ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}} : ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}} +: ${DB_NAME:=${DB_ENV_POSTGRES_DB_NAME:=${POSTGRES_DB_NAME:='odoo'}}} DB_ARGS=() function check_config() { @@ -27,6 +28,7 @@ check_config "db_host" "$HOST" check_config "db_port" "$PORT" check_config "db_user" "$USER" check_config "db_password" "$PASSWORD" +check_config "db_name" "$DB_NAME" case "$1" in -- | odoo) diff --git a/18.0/wait-for-psql.py b/18.0/wait-for-psql.py index a55f440..102f438 100755 --- a/18.0/wait-for-psql.py +++ b/18.0/wait-for-psql.py @@ -9,6 +9,7 @@ if __name__ == '__main__': arg_parser = argparse.ArgumentParser() arg_parser.add_argument('--db_host', required=True) arg_parser.add_argument('--db_port', required=True) + arg_parser.add_argument('--db_name', required=True) arg_parser.add_argument('--db_user', required=True) arg_parser.add_argument('--db_password', required=True) arg_parser.add_argument('--timeout', type=int, default=5) @@ -18,7 +19,7 @@ if __name__ == '__main__': start_time = time.time() while (time.time() - start_time) < args.timeout: try: - conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname='postgres') + conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname=args.db_name) error = '' break except psycopg2.OperationalError as e: