Skip to content

Commit

Permalink
Fixing a Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoApp committed Apr 24, 2023
1 parent 06a5a2e commit 49ab9ac
Show file tree
Hide file tree
Showing 79 changed files with 6,083 additions and 479 deletions.
2 changes: 0 additions & 2 deletions .devcontainer/Dockerfile

This file was deleted.

16 changes: 2 additions & 14 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"name": "Anythink Development Container",
"build": {
"dockerfile": "Dockerfile",
"args": { "VARIANT": "ubuntu-22.04" }
},

"image": "public.ecr.aws/v0a2l7y2/wilco/anythink-devcontainer:latest",
"forwardPorts": [3000, 3001, 5433, 27017],
"portsAttributes": {
"3000": {
Expand Down Expand Up @@ -32,15 +28,7 @@
"onAutoForward": "silent"
}
},
"postAttachCommand": "/bin/bash .devcontainer/setup.sh",

"features": {
"docker-in-docker": "latest",
"github-cli": "latest",
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
}
},
"postCreateCommand": "/bin/bash .devcontainer/setup.sh",

"settings": {
"extensions.ignoreRecommendations": true,
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/open_port.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sleep 10 && gh codespace ports visibility 3000:public -c $CODESPACE_NAME
sleep 10 && gh codespace ports visibility 3000:public 3001:public -c $CODESPACE_NAME
4 changes: 2 additions & 2 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
WILCO_ID="`cat .wilco`"
ENGINE_EVENT_ENDPOINT="${ENGINE_BASE_URL}/users/${WILCO_ID}/event"
CODESPACE_BACKEND_HOST="${CODESPACE_NAME}-3000.githubpreview.dev"
CODESPACE_BACKEND_HOST="${CODESPACE_NAME}-3000.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"
CODESPACE_BACKEND_URL="https://${CODESPACE_BACKEND_HOST}"

# Update engine that codespace started for user
Expand All @@ -17,7 +17,7 @@ echo "printf \"\n=============================================\n\"" >> ~/.bashrc
echo "gh codespace ports -c $CODESPACE_NAME" >> ~/.bashrc
echo "printf \"=============================================\n\"" >> ~/.bashrc
echo "printf \"(Once docker-compose is up and running, you can access the frontend and backend using the above urls)\n\"" >> ~/.bashrc
echo "printf \"\n👉 Type: \\\`docker-compose up\\\` to run the project. 👈\n\n\"" >> ~/.bashrc
echo "printf \"\n\x1b[31m \x1b[1m👉 Type: \\\`docker-compose up\\\` to run the project. 👈\n\n\"" >> ~/.bashrc

# Change backend port visibility to public
echo "(&>/dev/null .devcontainer/open_port.sh &)" >> ~/.bashrc
54 changes: 0 additions & 54 deletions .github/workflows/heroku.yml

This file was deleted.

157 changes: 157 additions & 0 deletions .github/workflows/k8s.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: Build and deploy to Kubernetes
on:
push:
branches:
- main

concurrency:
group: k8s
cancel-in-progress: true

jobs:
check-kubernetes-enabled:
runs-on: ubuntu-20.04
outputs:
kubernetes-enabled: ${{ steps.kubernetes-flag-defined.outputs.DEFINED }}
steps:
- id: kubernetes-flag-defined
if: "${{ env.ENABLE_KUBERNETES != '' }}"
run: echo "DEFINED=true" >> $GITHUB_OUTPUT
env:
ENABLE_KUBERNETES: ${{ secrets.ENABLE_KUBERNETES }}

check-secret:
runs-on: ubuntu-20.04
needs: [check-kubernetes-enabled]
outputs:
aws-creds-defined: ${{ steps.aws-creds-defined.outputs.DEFINED }}
kubeconfig-defined: ${{ steps.kubeconfig-defined.outputs.DEFINED }}
if: needs.check-kubernetes-enabled.outputs.kubernetes-enabled == 'true'
steps:
- id: aws-creds-defined
if: "${{ env.AWS_ACCESS_KEY_ID != '' && env.AWS_SECRET_ACCESS_KEY != '' }}"
run: echo "DEFINED=true" >> $GITHUB_OUTPUT
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- id: kubeconfig-defined
if: "${{ env.KUBECONFIG != '' }}"
run: echo "DEFINED=true" >> $GITHUB_OUTPUT
env:
KUBECONFIG: ${{ secrets.KUBECONFIG }}

build-backend:
name: Build backend image
runs-on: ubuntu-20.04
needs: [check-secret]
if: needs.check-secret.outputs.aws-creds-defined == 'true'
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Set the image tag
run: echo IMAGE_TAG=${GITHUB_REPOSITORY/\//-}-latest >> $GITHUB_ENV

- name: Set repository name
run: |
if [ ${{ secrets.CLUSTER_ENV }} == 'staging' ]; then
echo "REPO_NAME=staging-anythink-backend" >> $GITHUB_ENV
else
echo "REPO_NAME=anythink-backend" >> $GITHUB_ENV
fi
- name: Build, tag, and push backend image to Amazon ECR
id: build-image-backend
run: |
docker build \
-t ${{ steps.login-ecr.outputs.registry }}/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} \
-f backend/Dockerfile.aws \
.
docker push ${{ steps.login-ecr.outputs.registry }}/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }}
build-frontend:
name: Build frontend images
runs-on: ubuntu-20.04
needs: [check-secret]
if: needs.check-secret.outputs.aws-creds-defined == 'true'
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Set the image tag
run: echo IMAGE_TAG=${GITHUB_REPOSITORY/\//-}-latest >> $GITHUB_ENV

- name: Set repository name
run: |
if [ ${{ secrets.CLUSTER_ENV }} == 'staging' ]; then
echo "REPO_NAME=staging-anythink-frontend" >> $GITHUB_ENV
else
echo "REPO_NAME=anythink-frontend" >> $GITHUB_ENV
fi
- name: Build, tag, and push frontend image to Amazon ECR
id: build-image-frontend
run: |
docker build \
-t ${{ steps.login-ecr.outputs.registry }}/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} \
-f frontend/Dockerfile.aws \
.
docker push ${{ steps.login-ecr.outputs.registry }}/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }}
deploy:
name: Deploy latest tag using helm
runs-on: ubuntu-20.04
if: needs.check-secret.outputs.kubeconfig-defined == 'true'
needs:
- build-frontend
- build-backend
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Create kube config
run: |
mkdir -p $HOME/.kube/
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
chmod 600 $HOME/.kube/config
- name: Install helm
run: |
curl -LO https://get.helm.sh/helm-v3.8.0-linux-amd64.tar.gz
tar -zxvf helm-v3.8.0-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
helm version
- name: Lint helm charts
run: helm lint ./charts/

- name: Set the image tag
run: echo IMAGE_TAG=${GITHUB_REPOSITORY/\//-}-latest >> $GITHUB_ENV

- name: Deploy
run: |
helm upgrade --install --timeout 10m anythink-market ./charts/ \
--set clusterEnv=${{ secrets.CLUSTER_ENV }} \
--set frontend.image.tag=${{ env.IMAGE_TAG }} \
--set backend.image.tag=${{ env.IMAGE_TAG }}
35 changes: 13 additions & 22 deletions .github/workflows/wilco-actions.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
on:
on:
pull_request:
branches:
- main

jobs:
wilco:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
timeout-minutes: 10
name: Pr checks

Expand All @@ -30,28 +30,19 @@ jobs:
- name: Use Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.9.13"

- name: Wilco checks
id: Wilco
uses: trywilco/actions@main
- uses: oNaiPs/secrets-to-env-action@v1
with:
owner: ${{ github.repository_owner }}
Lint:
runs-on: ubuntu-latest
timeout-minutes: 10
secrets: ${{ toJSON(secrets) }}

defaults:
run:
working-directory: frontend
steps:
- name: Check out project
uses: actions/checkout@v2
- name: Lint code
- name: Setup Node for Wilco Checks
uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn'
cache-dependency-path: frontend/yarn.lock
- run: yarn add lint
- run: yarn lint
node-version: "16"

- name: Wilco checks
id: Wilco
uses: trywilco/actions@main
with:
engine: ${{ secrets.WILCO_ENGINE_URL }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/backend/node_modules
/frontend/node_modules
/.wilco-helpers/node_modules
/tests/e2e/node_modules
/.pnp
.pnp.js

Expand Down
12 changes: 12 additions & 0 deletions anythink_ack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
sleep 10s

echo "Welcome to"
echo " _ _ _ _ _ "
echo " / \ _ __ _ _ | |_ | |__ (_) _ __ | | __ "
echo " / _ \ | '_ \ | | | | | __| | '_ \ | | | '_ \ | |/ / "
echo " / ___ \ | | | | | |_| | | |_ | | | | | | | | | | | < "
echo " /_/ \_\ |_| |_| \__, | \__| |_| |_| |_| |_| |_| |_|\_\ "
echo " |___/ "

echo '\n\e]8;;http://anythink.wilco.gg/chat\e\\Click here\e]8;;\e\\ to go back to Snack'
11 changes: 1 addition & 10 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
FROM python:3.9.13
FROM public.ecr.aws/v0a2l7y2/wilco/anythink-backend-python:latest

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN pip install poetry==1.2.0

ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh /wait-for-it.sh

RUN chmod +x /wait-for-it.sh
15 changes: 15 additions & 0 deletions backend/Dockerfile.aws
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.9.13

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN pip install poetry==1.2.0

# Pre-install poetry packages
WORKDIR /usr/src
COPY backend ./backend
COPY .wilco ./.wilco
WORKDIR /usr/src/backend
RUN poetry install
RUN poetry export -f "requirements.txt" --without-hashes --with-credentials > "requirements.txt"
2 changes: 0 additions & 2 deletions backend/Procfile

This file was deleted.

Loading

0 comments on commit 49ab9ac

Please sign in to comment.