-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enable github workflow which allows us to autocommit * Adopt the python based version string identifier format * Go back to pre stable versioning to align with semantic versioning * Only build dataapi on pushes to master
- Loading branch information
Showing
4 changed files
with
54 additions
and
16 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,14 @@ name: Build and Deploy Docker Image for dataapi | |
on: | ||
push: | ||
branches: | ||
- backend-v2024.2.0 | ||
#paths: | ||
# - "api/fastapi/**" | ||
- master | ||
paths: | ||
- "api/fastapi/**" | ||
- ".github/workflows/build_dataapi.yml" | ||
|
||
env: | ||
oonidataapi_dir: ./api/fastapi | ||
IMAGE_NAME: ooni/dataapi | ||
DOCKERFILE_PATH: ./api/fastapi/ | ||
|
||
jobs: | ||
build_and_push: | ||
|
@@ -24,25 +25,62 @@ jobs: | |
username: ${{ vars.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Format version number | ||
- name: Format version information | ||
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" | ||
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8) | ||
BUILD_LABEL="${DATE}-${SHORT_SHA}" | ||
echo "build_label=$BUILD_LABEL" >> "$GITHUB_OUTPUT" | ||
VERSION_NUMBER=$(cat ${{ env.oonidataapi_dir }}/pyproject.toml | grep 'version =' | awk -F '"' '{print $2}') | ||
echo "version_number=$VERSION_NUMBER" >> "$GITHUB_OUTPUT" | ||
- name: Build and Push Docker Image | ||
env: | ||
DOCKERFILE_PATH: ${{ env.oonidataapi_dir }} | ||
run: | | ||
BUILD_LABEL=${{ steps.version.outputs.tag }} | ||
TAG_LATEST=$IMAGE_NAME:latest | ||
TAG_ENVIRONMENT=$IMAGE_NAME:production | ||
TAG_VERSION=$IMAGE_NAME:$BUILD_LABEL | ||
TAG_BUILD_LABEL=$IMAGE_NAME:${{ steps.version.outputs.build_label }} | ||
TAG_VERSION=$IMAGE_NAME:v${{ steps.version.outputs.version_number }} | ||
# 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 | ||
docker build --build-arg BUILD_LABEL=${{ steps.version.outputs.build_label }} \ | ||
-t $TAG_BUILD_LABEL \ | ||
-t $TAG_ENVIRONMENT \ | ||
-t $TAG_LATEST \ | ||
-t $TAG_VERSION \ | ||
$DOCKERFILE_PATH | ||
# Push all tags | ||
docker push $TAG_BUILD_LABEL | ||
docker push $TAG_ENVIRONMENT | ||
docker push $TAG_LATEST | ||
docker push $TAG_VERSION | ||
docker push $TAG_ENVIRONMENT | ||
- name: Checkout ooni/devops | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: "ooni/devops" # Replace with your repository's name | ||
ssh-key: ${{ secrets.OONI_DEVOPS_DEPLOYKEY }} | ||
path: "ooni-devops" | ||
ref: "tf-actions" | ||
|
||
- name: Bump version of dataapi | ||
run: | | ||
jq --arg value "v${{ steps.version.outputs.version_number }}" \ | ||
'(.ooni_service_config.dataapi_version) = $value' \ | ||
${BASE_DIR}/terraform.tfvars.json > ${BASE_DIR}/terraform.tfvars.json.tmp \ | ||
&& mv ${BASE_DIR}/terraform.tfvars.json.tmp ${BASE_DIR}/terraform.tfvars.json | ||
env: | ||
BASE_DIR: "ooni-devops/tf/environments/production" | ||
|
||
- name: Commit changes | ||
id: commit | ||
run: | | ||
cd ooni-devops | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "OONI Github Actions Bot" | ||
git add . | ||
git commit -m "auto: update oonidataapi package version to v${{ steps.version.outputs.version_number }}" || echo "No changes to commit" | ||
git push origin |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ Running: | |
|
||
``` | ||
poetry install | ||
poetry run uvicorn dataapi.main:app | ||
poetry run uvicorn oonidataapi.main:app | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "oonidataapi" | ||
version = "0.1.0" | ||
version = "0.2.0.dev1" | ||
description = "" | ||
authors = ["OONI <[email protected]>"] | ||
readme = "Readme.md" | ||
|