Merge pull request #29 from desci-labs/bump-contracts-pkg #86
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
on: | |
push: | |
branches: # array of glob patterns matching against refs/heads. Optional; defaults to all | |
- main # triggers on pushes that contain changes | |
- develop | |
# https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html | |
env: | |
AWS_DEFAULT_REGION: us-east-2 | |
AWS_DEFAULT_OUTPUT: json | |
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
CONTAINER_IMAGE: dpid-resolver | |
DOCKER_BUILDKIT: 1 | |
jobs: | |
test: | |
name: Run tests | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Prepare testing env | |
uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: ".nvmrc" | |
check-latest: false | |
cache: npm | |
- run: npm ci | |
- run: npm run test | |
build-and-push: | |
name: Build and deploy | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: hashicorp/setup-terraform@v1 | |
- uses: actions/checkout@v4 | |
# Add steps here like linting, testing, minification, etc. | |
- id: install-aws-cli | |
uses: unfor19/install-aws-cli-action@v1 | |
with: | |
version: 1 | |
- uses: prepor/action-aws-iam-authenticator@master | |
- run: aws-iam-authenticator version | |
- name: Install Kubectl | |
run: | | |
#$(curl -Ls https://dl.k8s.io/release/stable.txt) | |
version=v1.23.6 | |
echo "using kubectl@$version" | |
curl -sLO "https://dl.k8s.io/release/$version/bin/linux/amd64/kubectl" -o kubectl | |
chmod +x kubectl | |
mv kubectl /usr/local/bin | |
mkdir $HOME/.kube | |
sudo apt-get update | |
sudo apt-get install less | |
echo ${{ secrets.KUBE_CONFIG_DATA }} | base64 --decode > $HOME/.kube/config | |
aws sts get-caller-identity | |
kubectl describe deployments | |
- name: Build and tag the image (DEV) | |
if: github.ref == 'refs/heads/develop' | |
run: | | |
# Build and tag the image | |
docker build \ | |
--build-arg NODE_VERSION=$(< .nvmrc) \ | |
-t $CONTAINER_IMAGE-dev:latest \ | |
-t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev \ | |
. | |
- name: Build and tag the image (PROD) | |
if: github.ref == 'refs/heads/main' | |
run: | | |
# Build and tag the image | |
docker build \ | |
--build-arg NODE_VERSION=$(< .nvmrc) \ | |
-t $CONTAINER_IMAGE:latest \ | |
-t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE \ | |
. | |
# Add additional steps here like scanning of image | |
# Only push to registry on dev | |
- name: Push (DEV) | |
if: github.ref == 'refs/heads/develop' | |
run: | | |
# Push image to AWS ECR | |
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com | |
docker tag $CONTAINER_IMAGE-dev:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:${{ github.sha }} | |
docker tag $CONTAINER_IMAGE-dev:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:latest | |
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:${{ github.sha }} | |
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:latest | |
- name: Push (PROD) | |
if: github.ref == 'refs/heads/main' | |
run: | | |
# Push image to AWS ECR | |
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com | |
docker tag $CONTAINER_IMAGE:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE:${{ github.sha }} | |
docker tag $CONTAINER_IMAGE:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE:latest | |
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE:${{ github.sha }} | |
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE:latest | |
- name: Deploy to EKS (DEV) | |
# uses: steebchen/[email protected] | |
if: github.ref == 'refs/heads/develop' | |
run: | # defaults to latest kubectl binary version | |
kubectl apply -f kubernetes/deployment.dev.yaml | |
kubectl set image deployment/dpid-resolver-dev dpid-resolver-dev=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:${{ github.sha }} --record | |
- name: Deploy to EKS (PROD) | |
if: github.ref == 'refs/heads/main' | |
run: | # defaults to latest kubectl binary version | |
kubectl apply -f kubernetes/deployment.prod.yaml | |
kubectl set image deployment/dpid-resolver dpid-resolver=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE:${{ github.sha }} --record | |
- name: Verify EKS Deployment (DEV) | |
if: github.ref == 'refs/heads/develop' | |
run: | | |
kubectl rollout status deployment/dpid-resolver-dev | |
- name: Verify EKS Deployment (PROD) | |
if: github.ref == 'refs/heads/main' | |
run: | | |
kubectl rollout status deployment/dpid-resolver |