|
| 1 | +# The name of the workflow. |
| 2 | +name: Build and Deploy |
| 3 | + |
| 4 | +# Run the workflow when code is pushed to the main branch |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | +# Set environment variables |
| 11 | +env: |
| 12 | + MONGODB_URL: ${{ secrets.MONGODB_URL }} |
| 13 | + |
| 14 | +# This is the workflow that is being run. |
| 15 | +jobs: |
| 16 | + build-and-deploy: |
| 17 | + # This is telling GitHub to run the workflow on the latest version of Ubuntu. |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + # Checkout the code from the GitHub repository |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v2 |
| 23 | + |
| 24 | + # Install dependencies and run tests for the client application |
| 25 | + - name: Install Client |
| 26 | + working-directory: ./client |
| 27 | + run: | |
| 28 | + npm install |
| 29 | +
|
| 30 | + # Install dependencies, export environment variables to be used by application and run tests for the server application |
| 31 | + - name: Install Server |
| 32 | + working-directory: ./server |
| 33 | + run: | |
| 34 | + npm install |
| 35 | + export MONGODB_URL=$MONGODB_URL |
| 36 | +
|
| 37 | + # Build a Docker image for the client application |
| 38 | + - name: Build Client Docker Image |
| 39 | + working-directory: ./client |
| 40 | + # Build image with tag drbarzaga/job-portal:client |
| 41 | + run: | |
| 42 | + docker build -t drbarzaga/job-portal:client-${{github.run_number}} . |
| 43 | +
|
| 44 | + # Build a Docker image for the server application |
| 45 | + - name: Build Server Docker Image |
| 46 | + working-directory: |
| 47 | + ./server |
| 48 | + # Build image with tag drbarzaga/job-portal:server |
| 49 | + run: | |
| 50 | + docker build -t drbarzaga/job-portal:server-${{github.run_number}} . |
| 51 | +
|
| 52 | + # Login to Docker Hub using credentials from repository secrets |
| 53 | + - name: Login to Docker Hub |
| 54 | + uses: docker/login-action@v1 |
| 55 | + with: |
| 56 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 57 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 58 | + |
| 59 | + # Push the Docker images to Docker Hub |
| 60 | + - name: Push Docker Images to Docker Hub |
| 61 | + run: | |
| 62 | + docker push drbarzaga/job-portal:client-${{github.run_number}} |
| 63 | + docker push drbarzaga/job-portal:server-${{github.run_number}} |
0 commit comments