Overhaul CI, use reusable workflows (#830) #345
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
name: Build and Deploy | ||
on: | ||
# Push includes PR merge | ||
push: | ||
branches: | ||
- main | ||
- staging | ||
- development | ||
paths: | ||
# Workflow is triggered only if src changes | ||
- "src/**" | ||
# Allow manual trigger | ||
workflow_dispatch: | ||
jobs: | ||
pytest: | ||
uses: ./.github/workflows/r-pytest.yml | ||
Check failure on line 18 in .github/workflows/build_and_deploy.yml GitHub Actions / Build and DeployInvalid workflow file
|
||
with: | ||
image_tag: ci-${{ github.ref_name }} | ||
frontend-main-tests: | ||
uses: ./.github/workflows/r-frontend_tests.yml | ||
extract-versions: | ||
needs: | ||
- pytest | ||
- frontend-main-tests | ||
uses: ./.github/workflows/r-extract_versions.yml | ||
backend-build: | ||
uses: ./.github/workflows/r-build_backend.yml | ||
needs: extract-versions | ||
with: | ||
api_version: ${{ needs.extract-versions.outputs.api_version }} | ||
build_target: prod | ||
image_tags: | | ||
"ghcr.io/hotosm/fmtm/backend:${{ needs.extract-versions.outputs.api_version }}-${{ github.ref_name }}" | ||
"ghcr.io/hotosm/fmtm/backend:latest" | ||
frontend-main-build: | ||
uses: ./.github/workflows/r-build_frontend.yml | ||
needs: extract-versions | ||
with: | ||
environment: ${{ github.ref_name }} | ||
name: main | ||
app_version: ${{ needs.extract-versions.outputs.frontend_main_version }} | ||
build_target: prod | ||
image_tags: | | ||
"ghcr.io/hotosm/fmtm/frontend/main:${{ needs.extract-versions.outputs.frontend_main_version }}-${{ github.ref_name }}" | ||
"ghcr.io/hotosm/fmtm/frontend/main:latest" | ||
frontend-map-build: | ||
uses: ./.github/workflows/r-build_frontend.yml | ||
needs: extract-versions | ||
with: | ||
environment: ${{ github.ref_name }} | ||
name: fmtm_openlayer_map | ||
app_version: ${{ needs.extract-versions.outputs.frontend_map_version }} | ||
build_target: prod | ||
image_tags: | | ||
"ghcr.io/hotosm/fmtm/frontend/map:${{ needs.extract-versions.outputs.frontend_map_version }}-${{ github.ref_name }}" | ||
"ghcr.io/hotosm/fmtm/frontend/map:latest" | ||
smoke-test-backend: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- extract-versions | ||
- backend-build | ||
environment: | ||
name: ${{ github.ref_name }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Environment to .env | ||
env: | ||
API_VERSION: ${{ needs.extract-versions.outputs.api_version }} | ||
FRONTEND_MAIN_VERSION: ${{ needs.extract-versions.outputs.frontend_main_version }} | ||
FRONTEND_MAP_VERSION: ${{ needs.extract-versions.outputs.frontend_map_version }} | ||
run: | | ||
echo "${{ secrets.DOTENV }}" > .env | ||
echo "API_VERSION=${API_VERSION}" >> .env | ||
echo "FRONTEND_MAIN_VERSION=${FRONTEND_MAIN_VERSION}" >> .env | ||
echo "FRONTEND_MAP_VERSION=${FRONTEND_MAP_VERSION}" >> .env | ||
- name: Backend smoke test | ||
run: | | ||
docker compose --file docker-compose.deploy.yml pull api | ||
docker compose --file docker-compose.deploy.yml up api --exit-code-from api | ||
deploy-containers: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- extract-versions | ||
- smoke-test-backend | ||
environment: | ||
name: ${{ github.ref_name }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Environment to .env | ||
env: | ||
API_VERSION: ${{ needs.extract-versions.outputs.api_version }} | ||
FRONTEND_MAIN_VERSION: ${{ needs.extract-versions.outputs.frontend_main_version }} | ||
FRONTEND_MAP_VERSION: ${{ needs.extract-versions.outputs.frontend_map_version }} | ||
run: | | ||
echo "${{ secrets.DOTENV }}" > .env | ||
echo "API_VERSION=${API_VERSION}" >> .env | ||
echo "FRONTEND_MAIN_VERSION=${FRONTEND_MAIN_VERSION}" >> .env | ||
echo "FRONTEND_MAP_VERSION=${FRONTEND_MAP_VERSION}" >> .env | ||
- uses: webfactory/[email protected] | ||
with: | ||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
- name: Disable Host key verification | ||
# Hack to prevent "Host key verification failed". Should be replaced with a ssh-keyscan based solution | ||
run: echo "StrictHostKeyChecking no" >> ~/.ssh/config | ||
- name: Deploy | ||
run: | | ||
docker compose --file docker-compose.deploy.yml pull | ||
docker compose --file docker-compose.deploy.yml up --detach | ||
env: | ||
DOCKER_HOST: ${{ vars.DOCKER_HOST }} |