diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 0000000..ef3c71a --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,56 @@ +name: Build and Publish Docker Images to Docker Hub + +on: + push: + branches: + - main + paths: + - '**/*.py' + - '**/*.js' + - 'Dockerfile' + - '**/*.yml' + +jobs: + build: + runs-on: [self-hosted] + + steps: + # Step 1: Checkout the code + - name: Checkout code + uses: actions/checkout@v2 + + # Step 2: Set up Docker Buildx (only if needed on your self-hosted runner) + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # Step 3: Log in to Docker Hub + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} # Store Docker Hub username in GitHub secrets + password: ${{ secrets.DOCKER_PASSWORD }} # Store Docker Hub password in GitHub secrets + + # Step 4: Build the Backend Docker image + - name: Build Backend Docker image + run: | + docker build -t jonafoll/backend:${{ github.sha }} ./backend + docker tag jonafoll/backend:${{ github.sha }} your-username/backend:latest + + # Step 5: Build the Frontend Docker image + - name: Build Frontend Docker image + run: | + docker build -t your-username/frontend:${{ github.sha }} ./frontend + docker tag your-username/frontend:${{ github.sha }} your-username/frontend:latest + + # Step 6: Push the Backend Docker image to Docker Hub + - name: Push Backend Docker image to Docker Hub + run: | + docker push your-username/backend:${{ github.sha }} + docker push your-username/backend:latest + + # Step 7: Push the Frontend Docker image to Docker Hub + - name: Push Frontend Docker image to Docker Hub + run: | + docker push your-username/frontend:${{ github.sha }} + docker push your-username/frontend:latest +