Build/Test/Deploy Container #586
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/Test/Deploy Container | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- 'v*' | |
workflow_dispatch: | |
schedule: | |
# Run daily at 10:15 UTC (06:15 EDT/05:15 EST) | |
- cron: "15 10 * * *" | |
env: | |
IMAGE_NAME: oscal-editor-all-in-one | |
CONTAINER_NAME: test_container | |
TEST_TAG: "easydynaics/oscal-editor-all-in-one:testing" | |
jobs: | |
build_test_deploy: | |
name: Build, Test, and Deploy All-in-One Docker Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Install Tools | |
run: | | |
sudo apt-get update | |
sudo apt-get install jq xmlstarlet curl wget | |
# Get Default OSCAL Content for testing | |
- name: Pull OSCAL Content | |
uses: actions/checkout@v3 | |
with: | |
repository: EasyDynamics/oscal-demo-content | |
ref: "test-content" | |
path: all-in-one/oscal-content | |
- name: Set Up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
easydynamics/${{ env.IMAGE_NAME }} | |
ghcr.io/easydynamics/${{ env.IMAGE_NAME }} | |
tags: | | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=edge,branch=main | |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} | |
labels: | | |
org.opencontainers.image.title=oscal-editor-all-in-one | |
org.opencontainers.image.description=Simple Docker deployment of the back-end services and web-based user interface for the OSCAL Editor | |
org.opencontainers.image.vendor=Easy Dynamics | |
# Build the Docker image, and load it locally so it can be run for testing | |
- name: Build Docker Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./all-in-one | |
push: false | |
load: true | |
provenance: false | |
tags: ${{ env.TEST_TAG }} | |
labels: ${{ steps.meta.outputs.labels }} | |
# Run container in the background, exposing the port that | |
# Cypress uses to run the tests. | |
- name: Run Docker Container for Tests | |
run: | | |
chmod -R go+w $(pwd)/all-in-one/oscal-content; | |
ls -al $(pwd)/all-in-one/oscal-content; | |
docker run --rm -p 8080:8080 \ | |
-v $(pwd)/all-in-one/oscal-content:/app/oscal-content \ | |
--name ${CONTAINER_NAME} ${TEST_TAG} & | |
# Give the container time to start before starting to hammer it with tests | |
- name: Wait 10 sec | |
run: | | |
sleep 10 | |
- name: Run Cypress Tests | |
uses: cypress-io/github-action@v5 | |
with: | |
spec: cypress/e2e/**/*.cy.js | |
working-directory: end-to-end-tests | |
- name: Emit Docker Container Logs to file | |
if: always() | |
run: | | |
docker logs ${CONTAINER_NAME} &> container-logs.txt | |
- name: Upload Docker Container Logs | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: docker-logs | |
path: container-logs.txt | |
# Upload the screenshots and videos of a Cypress test failure | |
# to the artifacts of this workflow on GitHub | |
- name: Upload Cypress Artifacts | |
uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: cypress-results | |
path: | | |
./end-to-end-tests/cypress/screenshots | |
./end-to-end-tests/cypress/videos | |
- name: Stop Running Container | |
run: | |
docker stop ${CONTAINER_NAME} | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push to Container Registries | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./all-in-one | |
push: true | |
provenance: false | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
# This uses the peter-evans workflow: https://github.com/peter-evans/dockerhub-description | |
- name: Update Docker Hub Short-Description & Overview | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
repository: easydynamics/oscal-editor-all-in-one | |
short-description: A back-end service and web-based UI for the OSCAL Editor. | |
readme-filepath: all-in-one/README.md |