Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
megahirt committed Jan 13, 2022
2 parents 9026c4b + 8faf84a commit d0543e3
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 126 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/build-and-deploy-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,16 @@ on:
push:
tags:
- "v*"
branches:
- staging

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
environment:
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
runs-on: ubuntu-latest

steps:
- name: What version of Make is installed
run: make --version

- name: What version of Docker is installed
run: docker --version

- name: What version of Docker-Compose is installed
run: docker-compose --version

- name: CPU info
run: cat /proc/cpuinfo

- name: RAM info
run: free

- name: Disk info
run: df -h

build-n-publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set BUILD_VERSION for Staging
if: github.ref == 'refs/heads/staging'
run: |-
echo "BUILD_VERSION=staging-$GITHUB_SHA" >> "$GITHUB_ENV"
echo "BUILD_VERSION_LATEST=staging" >> "$GITHUB_ENV"
- name: Set BUILD_VERSION for Production from git tag
if: startsWith(github.ref, 'refs/tags/v')
# define BUILD_VERSION as stripping off initial 11 characters, i.e. "refs/tags/v"
run: |-
echo "BUILD_VERSION=$(echo ${GITHUB_REF:11})" >> "$GITHUB_ENV"
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/build-and-publish-adhoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ name: Publish ad-hoc image to Docker Hub

# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#on
on:
push:
paths:
- '**build-and-publish-adhoc.yml'
workflow_dispatch:
inputs:
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputsinput_id
tag:
description: Docker tag to publish
required: true

jobs:
build-n-publish:
runs-on: ubuntu-latest

env:
IMAGE: sillsdev/web-languageforge:pr-1247-blue
IMAGE: sillsdev/web-languageforge

steps:
- uses: actions/checkout@v2

- name: Build and tag app
run: docker build -t ${{ env.IMAGE }}-${GITHUB_SHA} -f docker/app/Dockerfile .
run: docker build -t ${{ env.IMAGE }}:${{ github.event.inputs.tag }} -f docker/app/Dockerfile .

- name: Log in to Docker Hub
uses: docker/login-action@v1
Expand All @@ -27,4 +30,4 @@ jobs:

- name: Publish image
run: |
docker push ${{ env.IMAGE }}-${GITHUB_SHA}
docker push ${{ env.IMAGE }}:${{ github.event.inputs.tag }}
29 changes: 29 additions & 0 deletions .github/workflows/build-and-publish-base-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build and publish a base PHP image for LF

# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#on
on:
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build-n-publish:
runs-on: ubuntu-latest

env:
IMAGE: sillsdev/web-languageforge:base-php

steps:
- uses: actions/checkout@v2

- name: Build and tag base image
run: docker build -t ${{ env.IMAGE }} -f docker/base-php/Dockerfile .

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

- name: Publish image
run: |
docker push ${{ env.IMAGE }}
59 changes: 59 additions & 0 deletions .github/workflows/deployment-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Deploy to staging

# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#on
on:
push:
branches:
- develop

jobs:
build:
runs-on: ubuntu-latest

outputs:
IMAGE: ${{ steps.image.outputs.NAMESPACE }}:${{ steps.image.outputs.TAG }}

steps:
-
uses: actions/checkout@v2
-
name: Build app
working-directory: ./docker/
run: docker-compose build --build-arg ENVIRONMENT=production app
-
name: Check unit tests
working-directory: ./docker/
run: make unit-tests
# -
# name: Check e2e tests
# working-directory: ./docker/
# run: make e2e-tests
-
name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
-
name: Establish image name
id: image
run: |
echo ::set-output name=NAMESPACE::sillsdev/web-languageforge
echo ::set-output name=TAG::develop-$(date +%Y%m%d)-${{ github.sha }}
-
name: Tag images
run: docker tag lf-app ${{ steps.image.outputs.NAMESPACE }}:${{ steps.image.outputs.TAG }}
-
name: Publish image
run: docker push ${{ steps.image.outputs.NAMESPACE }}:${{ steps.image.outputs.TAG }}

deploy:
runs-on: [self-hosted, languageforge]

needs: build

steps:
-
uses: sillsdev/common-github-actions/install-kubectl@v1
-
run: kubectl --context ${{ secrets.LTOPS_K8S_STAGING_CONTEXT }} set image deployment/app app=${{ needs.build.outputs.IMAGE }}
21 changes: 21 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run unit tests

# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#on
on:
pull_request:

push:
branches:
- staging

jobs:
unit-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run unit tests
working-directory: ./docker/
run: make unit-tests

44 changes: 21 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,28 @@ To report an issue using the **Language Forge** service, email "languageforgeiss

## Special Thanks To ##
- ![BrowserStack Logo](readme_images/browserstack-logo.png "BrowserStack") for mobile device testing.
-
[![Bugsnag logo](readme_images/bugsnag-logo.png "Bugsnag")](https://bugsnag.com/blog/bugsnag-loves-open-source) for error reporting.
- [![Bugsnag logo](readme_images/bugsnag-logo.png "Bugsnag")](https://bugsnag.com/blog/bugsnag-loves-open-source) for error reporting.

## Developers ##

We use [Gitflow](http://nvie.com/posts/a-successful-git-branching-model/) mostly, however we do not utilize a `develop` branch. All work starts and returns to the `master` branch. Deployment of software to a staging and/or a production environment occur through the use of the respective branches being fast-forwarded to the appropriate commit on `master` which will in turn kick off our automated deployment processes.
We use a modified [Gitflow](http://nvie.com/posts/a-successful-git-branching-model/) process to manage changes.

| Master Branch | Staging Branch (for testing) | Production Branch |
| ------------- | --------- | ----------- |
| `master` | `staging` | `prod` |
### Typical ###
1. Create a branch off of `develop`
1. Create a PR back into `develop`
1. Once approved and merged, test those changes on [qa.languageforge.org](https://qa.languageforge.org)
1. Once you are satisifed with the changes, coordinate with the team to deliver those changes to the production environment
1. Team leads will determine when the right time to cut a release, i.e., tag and deploy, typically this should be within a day or two

### CI Builds ###

Status of builds from our continuous integration (CI) [server](https://build.palaso.org):

| PHP Unit Tests | E2E Tests |
| ----------- | ---------- |
| [![Build Status](https://build.palaso.org/app/rest/builds/buildType:LanguageForgeDocker_PhpTests/statusIcon.svg)](https://build.palaso.org/buildConfiguration/LanguageForgeDocker_PhpTests) | [![Build Status](https://build.palaso.org/app/rest/builds/buildType:LanguageForgeDocker_E2eTests/statusIcon.svg)](https://build.palaso.org/buildConfiguration/LanguageForgeDocker_E2eTests) |
### Exception ###
1. There may be times when it's necessary to create a branch off of `master` (e.g. a hotfix for the production environment)
1. Coordinate with the team to deliver those changes to the production environment
1. Team leads will determine when the right time to cut a release, i.e., tag and deploy, this would likely be right away under these exceptional circumstances

### Deployed Sites ###

| Staging | Production |
| -- | ---- |
| - | - |
| [qa.languageforge.org](https://qa.languageforge.org) | [languageforge.org](https://languageforge.org) |

## Style Guides ##
Expand Down Expand Up @@ -85,13 +84,13 @@ Other useful resources:
> Sometimes there may be a need to hit the locally running app from a device other than the machine the app is running on. In order to do that, you'll need to do the following:
> 1. Figure out your local ip address
> 1. Access the app via http at that address
>
>
> On a Mac for example:
> ```
> ifconfig | grep broadcast
> inet 192.168.161.99 netmask 0xfffffc00 broadcast 192.168.163.255
> ```
>
>
> then hit `http://192.168.161.99` from your phone or other device on the same network.
>
> NOTE: disabling cache on your device may not be trivial, you'll either need to wipe the site settings on your device's browser or you'll need to do it via USB debugging.
Expand Down Expand Up @@ -169,7 +168,7 @@ After a minute or two, your source or test changes should be applied and you sho

### Building for deployment

1. Refer to `/.github/workflows/build-and-deploy-images.yml` for build commands.
1. Refer to `/.github/workflows/build-and-deploy-images.yml` for production build commands and `/.github/workflows/deployment-staging.yml` for staging build commands.

### Visual Studio Code ###

Expand All @@ -188,7 +187,7 @@ To debug the Language Forge application locally, follow these steps:
- In VS Code, set a breakpoint on a line of code that should be executed
- Click on the `Run and Debug` area of VS Code, then click the green play icon next to `XDebug` in the configuration dropdown.

![XDebug](readme_images/xdebug1.png "Debugging with XDebug")]
![XDebug](readme_images/xdebug1.png "Debugging with XDebug")]

- The VSCode status bar will turn orange when XDebug is active
- open the application in your web browser (`https://localhost`) and use the application such that you execute the code where you have a breakpoint set
Expand All @@ -207,7 +206,7 @@ To debug the PHP tests, follow these steps:
- In VS Code, set a breakpoint on a line of code in one of the PHP tests (in the `test/php` folder)
- Click on the `Run and Debug` area of VS Code, then click the green play icon next to `XDebug` in the configuration dropdown.

![XDebug](readme_images/xdebug1.png "Debugging with XDebug")]
![XDebug](readme_images/xdebug1.png "Debugging with XDebug")]

- The VSCode status bar will turn orange when XDebug is active
- run `make unit-tests` in the terminal
Expand Down Expand Up @@ -244,15 +243,14 @@ Language Forge is built to run in a containerized environment. For now, Kuberne
Staging deployments can be run with `VERSION=<some-docker-tag-or-semver> make deploy-staging`.

Current workflow:
1. merge commits into or make commits on `staging` branch
1. this will kick off the GHA (`.github/workflows/build-and-deploy-images.yml`) to build and publish the necessary images to Docker Hub (https://hub.docker.com/r/sillsdev/web-languageforge/tags)
1. then the deployment scripts can be run either manually or via the TeamCity deploy job
1. merge commits into or make commits on `develop` branch
1. this will kick off the GHA (`.github/workflows/deployment-staging.yml`) to build, publish the necessary images to Docker Hub (https://hub.docker.com/r/sillsdev/web-languageforge/tags) and deploy to the staging environment.

### Production ###
Production deployments can be run with `VERSION=<some-docker-tag-or-semver> make deploy-prod`.

Current workflow:
1. merge from `staging` into `master`
1. merge from `develop` into `master`
1. "Draft a new release" on https://github.com/sillsdev/web-languageforge/releases with a `v#.#.#` tag format
1. "Publish" the new release
1. this will kick off the GHA (`.github/workflows/build-and-deploy-images.yml`) to build and publish the necessary images to Docker Hub (https://hub.docker.com/r/sillsdev/web-languageforge/tags)
Expand Down
7 changes: 0 additions & 7 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ endif
.PHONY: unit-tests
unit-tests: build
docker-compose build test-php
ifeq ("$(TEAMCITY_VERSION)",$())
# developer machine
docker-compose run test-php
else
# teamcity CI
docker-compose run -e WEBSITE=languageforge.org --name unittests test-php
docker cp unittests:/var/www/PhpUnitTests.xml ..
endif

.PHONY: build
build:
Expand Down
51 changes: 3 additions & 48 deletions docker/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,69 +38,24 @@ FROM ${ENVIRONMENT}-ui-builder AS ui-builder
# artifacts built to /data/src/dist
RUN npm run build:${NPM_BUILD_SUFFIX}

# APP-BASE
FROM php:7.3.28-apache AS base-app

# install apt packages
# p7zip-full - used by LF application for unzipping lexicon uploads
# unzip - used by LF application for unzipping lexicon uploads
# gnupg2 - necessary for LFMerge package installation via SIL sources (will be uninstalled in production)
# curl - used by LF application
RUN apt-get update && apt-get -y install p7zip-full unzip gnupg2 curl && rm -rf /var/lib/apt/lists/*

# see https://github.com/mlocati/docker-php-extension-installer
# PHP extensions required by the LF application
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions gd mongodb intl

# install and configure LFMerge
# LFMerge required apt packages
# python - required by Mercurial (written in Python), which is bundled in the LFMerge apt package
# lfmerge - main package, from SIL sources
# rsyslog - lfmerge logs to rsyslog and expects this to exist
# logrotate - TODO: is this required?
# iputils-ping - Chorus (part of LFMerge) requires the "ping" command to be available on the command line
RUN curl -L http://linux.lsdev.sil.org/downloads/sil-testing.gpg | apt-key add - \
&& echo "deb http://linux.lsdev.sil.org/ubuntu bionic main" > /etc/apt/sources.list.d/linux-lsdev-sil-org.list \
&& apt-get update \
&& apt-get install --yes --no-install-recommends python lfmerge rsyslog logrotate iputils-ping \
&& rm -rf /var/lib/apt/lists/*
COPY docker/app/lfmerge.conf /etc/languageforge/conf/sendreceive.conf
COPY docker/app/lfmergeqm-background.sh /
RUN adduser www-data fieldworks \
&& chown -R www-data:www-data /var/lib/languageforge \
&& chmod 0755 /var/lib/languageforge \
&& mkdir -m 02775 -p /var/www/.local \
&& chown www-data:www-data /var/www/.local

# rsyslog customizations (imklog reads kernel messages, which isn't allowed or desired in Docker containers)
RUN sed -i '/load="imklog"/s/^/#/' /etc/rsyslog.conf

# php customizations
COPY docker/app/customizations.php.ini $PHP_INI_DIR/conf.d/

# apache2 customizations
RUN a2enmod headers rewrite
COPY docker/app/000-default.conf /etc/apache2/sites-enabled

# COMPOSER-BUILDER
# download composer app dependencies
# git - needed for composer install
FROM base-app AS composer-builder
FROM sillsdev/web-languageforge:base-php AS composer-builder
WORKDIR /composer
COPY src/composer.json src/composer.lock /composer/
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* \
&& install-php-extensions @composer && composer install

# PRODUCTION IMAGE
FROM base-app AS production-app
FROM sillsdev/web-languageforge:base-php AS production-app
RUN rm /usr/local/bin/install-php-extensions
RUN apt-get remove -y gnupg2
RUN mv $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini

# DEVELOPMENT IMAGE
FROM base-app AS development-app
FROM sillsdev/web-languageforge:base-php AS development-app
RUN install-php-extensions xdebug
COPY docker/app/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d
RUN mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini
Expand Down
Loading

0 comments on commit d0543e3

Please sign in to comment.