diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..5dd49e0 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,34 @@ +name: Build and Push Docker Image + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Build the Docker image + run: docker build . --file Dockerfile --tag atridad:${{ github.sha }} + + - name: Install doctl + uses: digitalocean/action-doctl@v2 + with: + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + + - name: Log in to DO Container Registry + run: doctl registry login --expiry-seconds 600 + + - name: Tag images + run: | + docker tag atridad:${{ github.sha }} registry.digitalocean.com/${{ secrets.DIGITALOCEAN_REGISTRY }}/atridotdad:${{ github.sha }} + docker tag atridad:${{ github.sha }} registry.digitalocean.com/${{ secrets.DIGITALOCEAN_REGISTRY }}/atridotdad:latest + + - name: Push images to DO Container Registry + run: | + docker push registry.digitalocean.com/${{ secrets.DIGITALOCEAN_REGISTRY }}/atridotdad:${{ github.sha }} + docker push registry.digitalocean.com/${{ secrets.DIGITALOCEAN_REGISTRY }}/atridotdad:latest diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..c08d672 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,42 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile + image: pollo:latest + command: ["/app"] + pull_policy: build + depends_on: + db: + condition: service_healthy + ports: + - "3002:3000" + environment: + - POSTGRES_HOST=db + - POSTGRES_PORT=5432 + - POSTGRES_DB=pollo + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - AUTH_SECRET=${AUTH_SECRET} + - ENCRYPTION_KEY=${ENCRYPTION_KEY} + - DEVMODE=${DEVMODE} + + db: + image: "postgres:16-alpine" + environment: + - POSTGRES_DB=pollo + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_USER=${POSTGRES_USER} + ports: + - 5432:5432 + volumes: + - pgdata:/var/lib/postgresql/data + restart: on-failure:3 + healthcheck: + test: ["CMD", "sh", "-c", "pg_isready -h db -p 5432 -U ${POSTGRES_USER}"] + interval: 10s + timeout: 5s + retries: 10 + +volumes: + pgdata: diff --git a/docker-compose.yml b/docker-compose.yml index c08d672..944be99 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,16 +1,14 @@ services: app: - build: - context: . - dockerfile: Dockerfile - image: pollo:latest + image: registry.digitalocean.com/himboapps/pollo:latest command: ["/app"] - pull_policy: build depends_on: db: condition: service_healthy ports: - "3002:3000" + networks: + - proxy environment: - POSTGRES_HOST=db - POSTGRES_PORT=5432 @@ -40,3 +38,8 @@ services: volumes: pgdata: + +networks: + proxy: + name: proxy + external: true