Skip to content

Commit

Permalink
updates to workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
yokwejuste committed Aug 18, 2024
1 parent 5f82aeb commit ef92ebf
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/main_dj237-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,54 @@ env:
jobs:
build-and-push:
runs-on: ubuntu-latest

outputs:
image_tag: ${{ steps.get-image-tag.outputs.image_tag }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Get short commit SHA
id: get-image-tag
run: echo "image_tag=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

- name: Log in to Azure Container Registry
uses: azure/docker-login@v2
with:
login-server: ${{ env.AZURE_CONTAINER_REGISTRY_LOGIN_SERVER }}
username: ${{ env.AZURE_CONTAINER_REGISTRY_USERNAME }}
password: ${{ env.AZURE_CONTAINER_REGISTRY_PASSWORD }}

- name: Create .env file from secret
run: echo "${{ secrets.PROJECT_SECRET }}" > .env

- name: Build and tag Docker image
run: |
docker build -f config/docker/Dockerfile -t ${{ env.AZURE_CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.APP_NAME }}:latest .
docker tag ${{ env.AZURE_CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.APP_NAME }}:latest ${{ env.AZURE_CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.APP_NAME }}:${{ env.IMAGE_TAG }}
- name: Push Docker image to ACR
run: |
docker push ${{ env.AZURE_CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.APP_NAME }}:latest
docker push ${{ env.AZURE_CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.APP_NAME }}:${{ env.IMAGE_TAG }}
deploy:
runs-on: ubuntu-latest
needs: build-and-push

steps:
- name: Log in to Azure Container Registry
uses: azure/docker-login@v2
with:
login-server: ${{ env.AZURE_CONTAINER_REGISTRY_LOGIN_SERVER }}
username: ${{ env.AZURE_CONTAINER_REGISTRY_USERNAME }}
password: ${{ env.AZURE_CONTAINER_REGISTRY_PASSWORD }}

- name: Pull and deploy the pinned Docker image
run: |
docker pull ${{ env.AZURE_CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.APP_NAME }}:${{ needs.build-and-push.outputs.image_tag }}
docker run -d --name ${{ env.APP_NAME }} --restart always -p 8000:8000 ${{ env.AZURE_CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.APP_NAME }}:${{ needs.build-and-push.outputs.image_tag }}
docker pull ${{ env.AZURE_CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.APP_NAME }}:latest
docker run -d --name ${{ env.APP_NAME }} --restart always -p 8000:8000 ${{ env.AZURE_CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.APP_NAME }}:latest

0 comments on commit ef92ebf

Please sign in to comment.