Skip to content

Commit e604522

Browse files
author
Robert Chu
committed
Updates terraform and deployment.
1 parent 5431315 commit e604522

8 files changed

Lines changed: 258 additions & 150 deletions

File tree

.github/workflows/publish-docker-images.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
name: Publish docker images
2+
on:
3+
push:
4+
branches:
5+
- main
6+
release:
7+
types: [published]
8+
jobs:
9+
publish-pypi:
10+
name: Publish script-runner to pypi
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Publish a Python distribution to PyPI
14+
uses: pypa/gh-action-pypi-publish@release/v1
15+
with:
16+
user: __token__
17+
password: ${{ secrets.PYPI_API_TOKEN }}
18+
19+
publish-docker:
20+
name: Publish script-runner to dockerhub
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Check out the repo
24+
uses: actions/checkout@v2
25+
- name: Prepare
26+
id: prep
27+
run: |
28+
PYTHON_IMAGE_TAG=alpine
29+
DOCKER_IMAGE=labflow/script-runner
30+
VERSION=latest
31+
if [[ $GITHUB_REF == refs/tags/* ]]; then
32+
VERSION=${GITHUB_REF#refs/tags/}
33+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
34+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
35+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
36+
VERSION=pr-${{ github.event.number }}
37+
fi
38+
TAGS="${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-latest,${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-${VERSION}"
39+
if [ "${{ github.event_name }}" = "push" ]; then
40+
TAGS="$TAGS,${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-sha-${GITHUB_SHA::8}"
41+
fi
42+
echo ::set-output name=version::${VERSION}
43+
echo ::set-output name=tags::${TAGS}
44+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
45+
echo ::set-output name=hashtag::"sha-${GITHUB_SHA::8}"
46+
echo ::set-output name=pyversion::"${PYTHON_IMAGE_TAG}"
47+
- name: Set up Docker Buildx
48+
id: buildx
49+
uses: docker/setup-buildx-action@v1
50+
- name: Cache Docker layers
51+
uses: actions/cache@v2.1.4
52+
with:
53+
path: /tmp/.buildx-cache
54+
key: ${{ runner.os }}-buildx-${{ github.sha }}
55+
restore-keys: |
56+
${{ runner.os }}-buildx-
57+
- name: Login to DockerHub
58+
if: github.event_name != 'pull_request'
59+
uses: docker/login-action@v1
60+
with:
61+
username: ${{ secrets.DOCKER_USERNAME }}
62+
password: ${{ secrets.DOCKER_PASSWORD }}
63+
- name: Push to Docker Hub
64+
uses: docker/build-push-action@v2
65+
with:
66+
context: ./docker
67+
file: ./Dockerfile
68+
builder: ${{ steps.buildx.outputs.name }}
69+
push: ${{ github.event_name != 'pull_request' }}
70+
tags: ${{ steps.prep.outputs.tags }}
71+
cache-from: type=local,src=/tmp/.buildx-cache
72+
cache-to: type=local,dest=/tmp/.buildx-cache
73+
labels: |
74+
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
75+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
76+
org.opencontainers.image.revision=${{ github.sha }}
77+
build-args: |
78+
SCRIPT_RUNNER_VERSION=${{ steps.prep.outputs.version }}
79+
PYTHON_IMAGE_TAG=${{ steps.prep.outputs.pyversion }}
80+
81+
deploy-aws-example:
82+
name: Deploy swabseq-analysis-example to AWS
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Configure AWS credentials
86+
uses: aws-actions/configure-aws-credentials@v1
87+
with:
88+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
89+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
90+
aws-region: us-west-1
91+
92+
- name: Setup Terraform tfvars
93+
uses: nowactions/envsubst@v1
94+
working-directory: ./examples/aws
95+
with:
96+
input: ./example.tfvars
97+
output: ./terraform.tfvars
98+
env:
99+
DNS_SUBDOMAIN: ${{secrets.DNS_SUBDOMAIN}}
100+
DNS_ZONE_ID: ${{secrets.DNS_ZONE_ID}}
101+
102+
- name: Setup Terraform
103+
working-directory: ./examples/aws
104+
uses: hashicorp/setup-terraform@v1
105+
106+
# - name: Terraform Format
107+
# id: fmt
108+
# run: terraform fmt -check
109+
110+
- name: Terraform Init
111+
id: init
112+
working-directory: ./examples/aws
113+
run: terraform init
114+
115+
- name: Terraform Plan
116+
id: plan
117+
working-directory: ./examples/aws
118+
if: github.event_name == 'pull_request'
119+
run: terraform plan -no-color
120+
continue-on-error: true
121+
122+
- uses: actions/github-script@v3
123+
working-directory: ./examples/aws
124+
if: github.event_name == 'pull_request'
125+
env:
126+
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
127+
with:
128+
github-token: ${{ secrets.GITHUB_TOKEN }}
129+
script: |
130+
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
131+
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
132+
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
133+
134+
<details><summary>Show Plan</summary>
135+
136+
\`\`\`${process.env.PLAN}\`\`\`
137+
138+
</details>
139+
140+
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
141+
142+
143+
await github.issues.createComment({
144+
issue_number: context.issue.number,
145+
owner: context.repo.owner,
146+
repo: context.repo.repo,
147+
body: output
148+
})
149+
150+
- name: Terraform Plan Status
151+
if: steps.plan.outcome == 'failure'
152+
run: exit 1
153+
154+
- name: Terraform Apply
155+
working-directory: ./examples/aws
156+
if: (github.event_name == 'release') || (github.event_name == 'push' && github.ref == 'refs/heads/main')
157+
run: terraform apply -auto-approve
158+
159+
deploy-azure-example:
160+
name: Deploy swabseq-analysis-example to Azure
161+
runs-on: ubuntu-latest
162+
steps:
163+
- name: Configure Azure credentials
164+
uses: azure/login@v1
165+
with:
166+
creds: ${{ secrets.AZURE_CREDENTIALS }}
167+
168+
- name: Setup Terraform tfvars
169+
uses: nowactions/envsubst@v1
170+
working-directory: ./examples/azure
171+
with:
172+
input: ./example.tfvars
173+
output: ./terraform.tfvars
174+
env:
175+
DNS_SUBDOMAIN: ${{secrets.DNS_SUBDOMAIN}}
176+
DNS_ZONE_NAME: ${{secrets.DNS_ZONE_NAME}}
177+
178+
- name: Setup Terraform
179+
working-directory: ./examples/azure
180+
uses: hashicorp/setup-terraform@v1
181+
182+
# - name: Terraform Format
183+
# id: fmt
184+
# run: terraform fmt -check
185+
186+
- name: Terraform Init
187+
id: init
188+
working-directory: ./examples/azure
189+
run: terraform init
190+
191+
- name: Terraform Plan
192+
id: plan
193+
working-directory: ./examples/azure
194+
if: github.event_name == 'pull_request'
195+
run: terraform plan -no-color
196+
continue-on-error: true
197+
198+
- uses: actions/github-script@v3
199+
working-directory: ./examples/azure
200+
if: github.event_name == 'pull_request'
201+
env:
202+
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
203+
with:
204+
github-token: ${{ secrets.GITHUB_TOKEN }}
205+
script: |
206+
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
207+
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
208+
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
209+
210+
<details><summary>Show Plan</summary>
211+
212+
\`\`\`${process.env.PLAN}\`\`\`
213+
214+
</details>
215+
216+
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
217+
218+
219+
await github.issues.createComment({
220+
issue_number: context.issue.number,
221+
owner: context.repo.owner,
222+
repo: context.repo.repo,
223+
body: output
224+
})
225+
226+
- name: Terraform Plan Status
227+
if: steps.plan.outcome == 'failure'
228+
run: exit 1
229+
230+
- name: Terraform Apply
231+
working-directory: ./examples/azure
232+
if: (github.event_name == 'release') || (github.event_name == 'push' && github.ref == 'refs/heads/main')
233+
run: terraform apply -auto-approve
234+

terraform/aws/example.tfvars

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
dns_name = "${DNS_NAME}"
2-
dns_zone_id = "${DNS_ZONE_ID}"
1+
dns_subdomain = "${DNS_SUBDOMAIN}"
2+
dns_zone_id = "${DNS_ZONE_ID}"
33

4-
auth0_domain = "${AUTH0_DOMAIN}"
5-
auth0_audience = "${AUTH0_AUDIENCE}"
6-
auth0_client_id = "${AUTH0_CLIENT_ID}"
7-
8-
image_tag = "${IMAGE_TAG}"
4+
image_tag = "sha-d59d449a"

terraform/aws/main.tf

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ module "swabseq_analysis" {
9090

9191
stack_name = var.stack_name
9292

93-
auth0_domain = var.auth0_domain
94-
auth0_audience = var.auth0_audience
95-
auth0_client_id = var.auth0_client_id
93+
auth_provider = "none"
9694

9795
ecs_task_execution_role_arn = aws_iam_role.labflow_role.arn
9896
ecs_task_execution_role_name = aws_iam_role.labflow_role.name
@@ -106,6 +104,6 @@ module "swabseq_analysis" {
106104
image = "labflow/swabseq-analysis-server-example"
107105
image_tag = var.image_tag
108106

109-
dns_name = var.dns_name
110-
dns_zone_id = var.dns_zone_id
107+
dns_subdomain = var.dns_subdomain
108+
dns_zone_id = var.dns_zone_id
111109
}

terraform/aws/variables.tf

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,14 @@ variable "stack_name" {
88
default = "swabseq-analysis-example"
99
}
1010

11-
variable "dns_name" {
11+
variable "dns_subdomain" {
1212
type = string
1313
}
1414

1515
variable "dns_zone_id" {
1616
type = string
1717
}
1818

19-
variable "auth0_domain" {
20-
type = string
21-
}
22-
23-
variable "auth0_audience" {
24-
type = string
25-
}
26-
27-
variable "auth0_client_id" {
28-
type = string
29-
}
30-
3119
variable "image_tag" {
3220
type = string
3321
default = "latest"

terraform/azure/example.tfvars

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
dns_subdomain = "${DNS_SUBDOMAIN}"
2-
dns_domain = "${DNS_DOMAIN}"
32
dns_zone_name = "${DNS_ZONE_NAME}"
43

5-
auth0_domain = "${AUTH0_DOMAIN}"
6-
auth0_audience = "${AUTH0_AUDIENCE}"
7-
auth0_client_id = "${AUTH0_CLIENT_ID}"
8-
9-
image_tag = "${IMAGE_TAG}"
4+
image_tag = "sha-d59d449a"

0 commit comments

Comments
 (0)