Skip to content

build-and-push-docker-image #15

build-and-push-docker-image

build-and-push-docker-image #15

name: build-and-push-docker-image
on:
push:
branches:
- main
workflow_run:
workflows: ["test-backend"]
types:
- completed
jobs:
# define job to build and publish docker image
build-and-push-docker-image:
if: github.event.workflow_run.conclusion == 'success'
# run only when code is compiling and tests are passing
runs-on: ubuntu-22.04
# steps to perform in job
steps:
- name: Login to DockerHub
run: docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_AUTH }}
#checkout your github code using actions/[email protected]
- name: Checkout code
uses: actions/[email protected]
- name: Build image and push backend
uses: docker/build-push-action@v3
with:
# relative path to the place where source code with Dockerfile is located
context: TP01/simple-api-student-main
# Note: tags has to be all lower-case
tags: ${{secrets.DOCKERHUB_USERNAME}}/tp01-api:latest
# build on feature branches, push only on main branch
push: ${{ github.ref == 'refs/heads/main' }}
- name: Build image and push database
uses: docker/build-push-action@v3
with:
# relative path to the place where source code with Dockerfile is located
context: TP01/db
# Note: tags has to be all lower-case
tags: ${{secrets.DOCKERHUB_USERNAME}}/tp01-postgres:latest
# build on feature branches, push only on main branch
push: ${{ github.ref == 'refs/heads/main' }}
- name: Build image and push http
uses: docker/build-push-action@v3
with:
# relative path to the place where source code with Dockerfile is located
context: TP01/web
# Note: tags has to be all lower-case
tags: ${{secrets.DOCKERHUB_USERNAME}}/tp01-web:latest
# build on feature branches, push only on main branch
push: ${{ github.ref == 'refs/heads/main' }}
- name: Build image and push frontend
uses: docker/build-push-action@v3
with:
# relative path to the place where source code with Dockerfile is located
context: TP03/devops-front-main
# Note: tags has to be all lower-case
tags: ${{secrets.DOCKERHUB_USERNAME}}/tp03-frontend:latest
# build on feature branches, push only on main branch
push: ${{ github.ref == 'refs/heads/main' }}