Faffio commited on
Commit
010ce41
·
1 Parent(s): 20e4b88

CD: Push to Docker Hub

Browse files
Files changed (1) hide show
  1. .github/workflows/ci_papeline.yaml +23 -7
.github/workflows/ci_papeline.yaml CHANGED
@@ -8,7 +8,7 @@ on:
8
  pull_request:
9
  branches: [ "main" ]
10
 
11
- # Appena attivato il trigger, viene avviato build docker sotto che richieste l'esecuzione di run_test, se ok parte la creazione dell'immagine docker
12
  jobs:
13
  # JOB 1: Esecuzione dei Test Automatici
14
  run_tests:
@@ -40,19 +40,35 @@ jobs:
40
 
41
  # JOB 2: Verifica della Build Docker
42
  # Questo job parte SOLO se "run_tests" ha successo (needs: run_tests)
43
- build_docker:
44
  needs: run_tests
45
  runs-on: ubuntu-latest
 
 
 
46
 
47
  steps:
48
  - name: Checkout code
49
  uses: actions/checkout@v3
50
-
51
- - name: Build Docker Image
52
- # Prova a costruire l'immagine. Se il Dockerfile è rotto, questo step fallisce.
53
- # E' solo un test, dopo che abbiamo fatto girare pytest su test_api.py, ora testiamo che il dockerfile funzioni creando l'immmagine che poi distruggiamo
54
- run: docker build -t reputation-monitor:test .
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  # I file vengono salvati nella repository PRIMA che il test parta. È il fatto che tu abbia "pushato" i file che sveglia il robot e gli fa iniziare il lavoro.
57
 
58
  # Ecco la sequenza temporale esatta:
 
8
  pull_request:
9
  branches: [ "main" ]
10
 
11
+ # Appena attivato il trigger, viene avviato build docker sotto (job2) che richieste l'esecuzione di run_test(job1), se ok parte la creazione dell'immagine docker
12
  jobs:
13
  # JOB 1: Esecuzione dei Test Automatici
14
  run_tests:
 
40
 
41
  # JOB 2: Verifica della Build Docker
42
  # Questo job parte SOLO se "run_tests" ha successo (needs: run_tests)
43
+ build_and_push_docker:
44
  needs: run_tests
45
  runs-on: ubuntu-latest
46
+ # Importante: Eseguiamo il push solo se siamo sul ramo 'main'
47
+ # (non vogliamo pushare immagini di test da altri rami)
48
+ if: github.ref == 'refs/heads/main' && github.event_name == 'push'
49
 
50
  steps:
51
  - name: Checkout code
52
  uses: actions/checkout@v3
 
 
 
 
 
53
 
54
+ # 1. Login su Docker Hub (usa i segreti che hai appena creato)
55
+ - name: Login to Docker Hub
56
+ uses: docker/login-action@v3
57
+ with:
58
+ username: ${{ secrets.DOCKER_USERNAME }}
59
+ password: ${{ secrets.DOCKER_PASSWORD }}
60
+
61
+ # 2. Build e Push vero e proprio
62
+ - name: Build and Push
63
+ run: |
64
+ # Usa la variabile ${{ secrets.DOCKER_USERNAME }}
65
+ IMAGE_TAG=${{ secrets.DOCKER_USERNAME }}/reputation-monitor:latest
66
+
67
+ echo "Building image: $IMAGE_TAG"
68
+ docker build -t $IMAGE_TAG .
69
+
70
+ echo "Pushing image to Docker Hub..."
71
+ docker push $IMAGE_TAG
72
  # I file vengono salvati nella repository PRIMA che il test parta. È il fatto che tu abbia "pushato" i file che sveglia il robot e gli fa iniziare il lavoro.
73
 
74
  # Ecco la sequenza temporale esatta: