Update pipeline.yml #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The name of the workflow. | |
name: Build and Deploy | |
# Run the workflow when code is pushed to the main branch | |
on: | |
push: | |
branches: | |
- main | |
# Set environment variables | |
env: | |
MONGODB_URL: ${{ secrets.MONGODB_URL }} | |
# This is the workflow that is being run. | |
jobs: | |
build-and-deploy: | |
# This is telling GitHub to run the workflow on the latest version of Ubuntu. | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the code from the GitHub repository | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
node-version: 20.x | |
# Install dependencies and run tests for the client application | |
- name: Install Client | |
working-directory: ./client | |
run: | | |
npm install | |
# Install dependencies, export environment variables to be used by application and run tests for the server application | |
- name: Install Server | |
working-directory: ./server | |
run: | | |
npm install | |
export MONGODB_URL=$MONGODB_URL | |
# Build a Docker image for the client application | |
- name: Build Client Docker Image | |
working-directory: ./client | |
# Build image with tag drbarzaga/job-portal:client | |
run: | | |
docker build -t drbarzaga/job-portal:client-${{github.run_number}} . | |
# Build a Docker image for the server application | |
- name: Build Server Docker Image | |
working-directory: | |
./server | |
# Build image with tag drbarzaga/job-portal:server | |
run: | | |
docker build -t drbarzaga/job-portal:server-${{github.run_number}} . | |
# Login to Docker Hub using credentials from repository secrets | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
node-version: 20.x | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# Push the Docker images to Docker Hub | |
- name: Push Docker Images to Docker Hub | |
run: | | |
docker push drbarzaga/job-portal:client-${{github.run_number}} | |
docker push drbarzaga/job-portal:server-${{github.run_number}} |