Skip to content

Commit

Permalink
Add github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Feb 1, 2024
1 parent e63aec6 commit 5ebaba6
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build_dataapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and Deploy Docker Image for dataapi

on:
push:
branches:
- 2024-refactor
#paths:
# - "api/fastapi/**"

env:
IMAGE_NAME: ooni/dataapi
DOCKERFILE_PATH: ./api/fastapi/

jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Format version number
id: version
run: |
DATE=$(date +'%Y%m%d')
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-4)
TAG="v${DATE}-${SHORT_SHA}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: Build and Push Docker Image
run: |
BUILD_LABEL=${{ steps.version.outputs.tag }}
TAG_LATEST=$IMAGE_NAME:latest
TAG_ENVIRONMENT=$IMAGE_NAME:production
TAG_VERSION=$IMAGE_NAME:$BUILD_LABEL
# Build Docker image with multiple tags
docker build --build-arg BUILD_LABEL=$BUILD_LABEL -t $TAG_LATEST -t $TAG_VERSION -t $TAG_ENVIRONMENT $DOCKERFILE_PATH
# Push all tags
docker push $TAG_LATEST
docker push $TAG_VERSION
docker push $TAG_ENVIRONMENT

0 comments on commit 5ebaba6

Please sign in to comment.