Skip to content

Commit

Permalink
Merge pull request #73 from silinternational/feature/github-actions
Browse files Browse the repository at this point in the history
Convert to GitHub Actions
  • Loading branch information
briskt authored Feb 28, 2024
2 parents 6e161e4 + 72e4ca0 commit 639c681
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Whitelist required files
!.env.encrypted
!codeship/*
!scripts/*
!lambda/*
!server/*
!u2fsimulator/*
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/test-deploy-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Test, Deploy, Publish

on:
push:

jobs:
tests:
name: Tests
runs-on: ubuntu-latest
env:
AWS_REGION: ${{ vars.AWS_REGION }}
STG_AWS_ACCESS_KEY_ID: ${{ vars.STG_AWS_ACCESS_KEY_ID }}
STG_AWS_SECRET_ACCESS_KEY: ${{ secrets.STG_AWS_SECRET_ACCESS_KEY }}
PRD_AWS_ACCESS_KEY_ID: ${{ vars.PRD_AWS_ACCESS_KEY_ID }}
PRD_AWS_SECRET_ACCESS_KEY: ${{ secrets.PRD_AWS_SECRET_ACCESS_KEY }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Test
run: docker-compose -f actions-services.yml run --rm test ./scripts/test.sh

deploy:
name: Deploy to AWS Lambda
needs: tests
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
env:
AWS_REGION: ${{ vars.AWS_REGION }}
STG_AWS_ACCESS_KEY_ID: ${{ vars.STG_AWS_ACCESS_KEY_ID }}
STG_AWS_SECRET_ACCESS_KEY: ${{ secrets.STG_AWS_SECRET_ACCESS_KEY }}
STG_LAMBDA_ROLE: ${{ vars.STG_LAMBDA_ROLE }}
STG_API_KEY_TABLE: ${{ vars.STG_API_KEY_TABLE }}
STG_WEBAUTHN_TABLE: ${{ vars.STG_WEBAUTHN_TABLE }}
PRD_AWS_ACCESS_KEY_ID: ${{ vars.PRD_AWS_ACCESS_KEY_ID }}
PRD_AWS_SECRET_ACCESS_KEY: ${{ secrets.PRD_AWS_SECRET_ACCESS_KEY }}
PRD_LAMBDA_ROLE: ${{ vars.PRD_LAMBDA_ROLE }}
PRD_API_KEY_TABLE: ${{ vars.PRD_API_KEY_TABLE }}
PRD_WEBAUTHN_TABLE: ${{ vars.PRD_WEBAUTHN_TABLE }}

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy
run: docker-compose -f actions-services.yml run --rm app ./scripts/deploy.sh

build-and-publish:
name: Build and Publish
needs: tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ vars.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ bootstrap
dockercfg

# credentials and other env files
aws.env
*.aes
local.env
.env
*.env
.cert/

# dev tools metadata
Expand Down
44 changes: 44 additions & 0 deletions actions-services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: "3"

services:
test:
build: .
environment:
AWS_ENDPOINT: dynamo:8000
AWS_DISABLE_SSL: "true"
API_KEY_TABLE: ApiKey
WEBAUTHN_TABLE: WebAuthn
LAMBDA_ROLE: placeholder
AWS_REGION: $AWS_REGION
GITHUB_REF_NAME: $GITHUB_REF_NAME
STG_AWS_ACCESS_KEY_ID: $STG_AWS_ACCESS_KEY_ID
STG_AWS_SECRET_ACCESS_KEY: $STG_AWS_SECRET_ACCESS_KEY
PRD_AWS_ACCESS_KEY_ID: $PRD_AWS_ACCESS_KEY_ID
PRD_AWS_SECRET_ACCESS_KEY: $PRD_AWS_SECRET_ACCESS_KEY
depends_on:
- dynamo

app:
build: .
working_dir: /src
environment:
AWS_REGION: $AWS_REGION
GITHUB_REF_NAME: $GITHUB_REF_NAME
STG_AWS_ACCESS_KEY_ID: $STG_AWS_ACCESS_KEY_ID
STG_AWS_SECRET_ACCESS_KEY: $STG_AWS_SECRET_ACCESS_KEY
STG_LAMBDA_ROLE: $STG_LAMBDA_ROLE
STG_API_KEY_TABLE: $STG_API_KEY_TABLE
STG_WEBAUTHN_TABLE: $STG_WEBAUTHN_TABLE
PRD_AWS_ACCESS_KEY_ID: $PRD_AWS_ACCESS_KEY_ID
PRD_AWS_SECRET_ACCESS_KEY: $PRD_AWS_SECRET_ACCESS_KEY
PRD_LAMBDA_ROLE: $PRD_LAMBDA_ROLE
PRD_API_KEY_TABLE: $PRD_API_KEY_TABLE
PRD_WEBAUTHN_TABLE: $PRD_WEBAUTHN_TABLE

dynamo:
image: amazon/dynamodb-local
environment:
AWS_ACCESS_KEY_ID: abc123
AWS_SECRET_ACCESS_KEY: abc123
AWS_DEFAULT_REGION: us-east-1
command: "-jar DynamoDBLocal.jar -sharedDb"
29 changes: 0 additions & 29 deletions codeship-services.yml

This file was deleted.

26 changes: 0 additions & 26 deletions codeship-steps.yml

This file was deleted.

File renamed without changes.
6 changes: 3 additions & 3 deletions codeship/deploy.sh → scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
"$DIR"/build.sh

# export appropriate env vars
if [ "${CI_BRANCH}" == "develop" ];
if [ "${GITHUB_REF_NAME}" == "develop" ];
then
STAGE="dev"
export AWS_ACCESS_KEY_ID="${STG_AWS_ACCESS_KEY_ID}"
Expand All @@ -21,7 +21,7 @@ then
export LAMBDA_ROLE="${STG_LAMBDA_ROLE}"
export API_KEY_TABLE="${STG_API_KEY_TABLE}"
export WEBAUTHN_TABLE="${STG_WEBAUTHN_TABLE}"
elif [ "${CI_BRANCH}" == "main" ];
elif [ "${GITHUB_REF_NAME}" == "main" ];
then
STAGE="production"
export AWS_ACCESS_KEY_ID="${PRD_AWS_ACCESS_KEY_ID}"
Expand All @@ -32,7 +32,7 @@ then
export API_KEY_TABLE="${PRD_API_KEY_TABLE}"
export WEBAUTHN_TABLE="${PRD_WEBAUTHN_TABLE}"
else
echo "deployments only happen from develop and main branches (branch: ${CI_BRANCH})"
echo "deployments only happen from develop and main branches (branch: ${GITHUB_REF_NAME})"
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion codeship/test.sh → scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e
set -x

# export appropriate AWS credentials for `serverless info`
if [ "${CI_BRANCH}" == "main" ];
if [ "${GITHUB_REF_NAME}" == "main" ];
then
STAGE="production"
export AWS_ACCESS_KEY_ID="${PRD_AWS_ACCESS_KEY_ID}"
Expand Down

0 comments on commit 639c681

Please sign in to comment.