diff --git a/.github/workflows/database.yml b/.github/workflows/database.yml index 0c969e3..65ef292 100644 --- a/.github/workflows/database.yml +++ b/.github/workflows/database.yml @@ -1,35 +1,34 @@ -name: database -on: [push] +name: Build and publish the database Docker Image + +on: + push: + branches: ['main'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: - database-creation: + build-and-push-image: runs-on: ubuntu-latest - services: - # Label used to access the service container - postgres: - image: postgres - env: - POSTGRES_PASSWORD: postgres - POSTGRES_DB: big-brother - # Set health checks to wait until postgres has started - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - # Maps tcp port 5432 on service container to the host - - 5432:5432 - steps: - name: Check out repository code uses: actions/checkout@v4 - - name: Install dependencies - run: pip3 install psycopg2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Connect to PostgreSQL - run: python3 database/db-creation.py - env: - POSTGRES_HOST: postgres - POSTGRES_PORT: 5432 \ No newline at end of file + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: ./database + push: true + tags: ghcr.io/${{ github.repository }}:latest \ No newline at end of file diff --git a/database/Dockerfile b/database/Dockerfile new file mode 100644 index 0000000..6fad284 --- /dev/null +++ b/database/Dockerfile @@ -0,0 +1,8 @@ +FROM postgres:latest + +COPY database/init_db.py /docker-entrypoint-initdb.d/ + +RUN apt-get update && apt-get install -y python3 python3-pip && \ + pip3 install psycopg2-binary + +EXPOSE 5432 diff --git a/database/db-creation.py b/database/init_db.py similarity index 100% rename from database/db-creation.py rename to database/init_db.py