-
Notifications
You must be signed in to change notification settings - Fork 11
148 lines (130 loc) · 4.75 KB
/
deploy-container-main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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