diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..48fd897 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +./CalendarReminder.Api/appsettings.json +./CalendarReminder.Api/appsettings.Development.json +.gitea +Dockerfile +docker-compose.yml \ No newline at end of file diff --git a/.env.example b/.env.example index 3a60c9c..5c837b7 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,10 @@ # Skopíruj tento súbor ako .env a vyplň hodnoty # cp .env.example .env +# Docker Hub +DOCKERHUB_USERNAME= +WATCHTOWER_TOKEN= + # Databáza DB_SERVER=192.168.1.68 DB_PORT=3306 diff --git a/.gitea/workflows/docker-build.yaml b/.gitea/workflows/docker-build.yaml new file mode 100644 index 0000000..1eafb79 --- /dev/null +++ b/.gitea/workflows/docker-build.yaml @@ -0,0 +1,37 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - master + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and Push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/calendarreminder-app:latest + cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/calendarreminder-app:buildcache + cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/calendarreminder-app:buildcache,mode=max + + - name: Trigger Watchtower deploy + run: | + curl -sf \ + -H "Authorization: Bearer ${{ secrets.WATCHTOWER_TOKEN }}" \ + http://${{ secrets.TRUENAS_IP }}:8085/v1/update diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/docker-compose.yml b/docker-compose.yml index 62bac06..a5e7bd6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,13 @@ services: app: - build: . + image: ${DOCKERHUB_USERNAME}/calendarreminder-app:latest ports: - "8080:8080" + depends_on: + db: + condition: service_healthy + labels: + - "com.centurylinklabs.watchtower.enable=true" environment: - ASPNETCORE_ENVIRONMENT=Production - ConnectionStrings__Default=Server=${DB_SERVER};Port=${DB_PORT};Database=${DB_NAME};User=${DB_USER};Password=${DB_PASSWORD}; @@ -32,3 +37,16 @@ services: timeout: 5s retries: 5 restart: unless-stopped + + watchtower: + image: containrrr/watchtower + ports: + - "8085:8080" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + environment: + - WATCHTOWER_LABEL_ENABLE=true + - WATCHTOWER_CLEANUP=true + - WATCHTOWER_HTTP_API_UPDATE=true + - WATCHTOWER_HTTP_API_TOKEN=${WATCHTOWER_TOKEN} + restart: unless-stopped