Skip to content

[CI] Move to appcd-dev action #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .appcd.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
version: 0.0.1
name: DogeApi
services:
dogeapi:
dtr: ghcr.io/appcd-dev/dogeapi/dogeapi
dtr: ghcr.io/appcd-demo/dogeapi/dogeapi
path: /
tag: latest
dockerFile: Dockerfile
language: Python
dockerFile: ./Dockerfile
95 changes: 33 additions & 62 deletions .github/workflows/appcd-iac-pr-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,22 @@ jobs:
ref: main
path: main_branch
fetch-depth: 1
- name: Generate IaC from Main Branch
- name: Generate IAC for main branch
env:
APPCD_TOKEN: ${{ secrets.APPCD_TOKEN }}
APPCD_URL: ${{ secrets.APPCD_URL }}
run: |
mkdir -p artifact/main/ ./artifact/tmp
docker run --rm \
--workdir=/app/scan \
-e APPCD_TOKEN=$APPCD_TOKEN \
-e APPCD_URL=$APPCD_URL \
-v ./main_branch:/app/scan \
-v ./artifact/tmp:/tmp \
-v ./artifact/main:/artifact/main \
--entrypoint=appcd \
ghcr.io/appcd-dev/appcd-dist/appcd-cli:v0.9.1 \
generate --mode ci --lang Python --log 2 --output=/artifact/main/.appcd/charts --iac-type Helm
cd artifact/main/.appcd/charts
unzip scan.zip && rm scan.zip && ls -latr && pwd
- name: Upload logs
uses: actions/upload-artifact@v2
uses: appcd-dev/action@v0.0.1
with:
cloud: 'aws'
language: 'Python'
outputDir: './artifact/main'
scanPath: './main_branch'
targetCompute: 'k8s'
- name: Upload main artifacts
uses: actions/upload-artifact@v4
with:
name: analyzer_logs_1
path: artifact
name: main_branch_artifacts
path: artifact/main
- name: Checkout PR Branch
uses: actions/checkout@v4
with:
Expand All @@ -50,58 +43,36 @@ jobs:
run: echo "branch=$(basename ${{ github.head_ref}})" >> $GITHUB_OUTPUT
- name: echo branch name
run: echo ${{ steps.extract_branch.outputs.branch }}
- name: Generate IaC from PR branch
- name: Generate IAC for PR branch
env:
APPCD_TOKEN: ${{ secrets.APPCD_TOKEN }}
APPCD_URL: ${{ secrets.APPCD_URL }}
run: |
mkdir -p artifact/${{ steps.extract_branch.outputs.branch }}/ ./artifact/tmp
docker run --rm \
--workdir=/app/scan \
-v ./pr_branch/:/app/scan \
-v ./artifact/${{ steps.extract_branch.outputs.branch }}:/artifact/${{ steps.extract_branch.outputs.branch }} \
-v ./artifact/tmp:/tmp \
-e APPCD_TOKEN=$APPCD_TOKEN \
-e APPCD_URL=$APPCD_URL \
--entrypoint=appcd \
ghcr.io/appcd-dev/appcd-dist/appcd-cli:v0.9.1 \
generate --mode ci --lang Python --log 2 --iac-type Helm --output=/artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts
cd artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts
unzip scan.zip && rm scan.zip && ls -latr
- name: Upload logs
uses: actions/upload-artifact@v2
uses: appcd-dev/action@v0.0.1
with:
name: analyzer_logs_2
path: artifact
- name: Copy infrastructure files if empty
run: |
cd pr_branch
mkdir -p infrastructure
if [ -z "$(ls -A infrastructure/)" ]; then
cp -r .appcd/infrastructure/app/rds/ infrastructure/
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add infrastructure/
git commit -m "Adds IaC dependency files"
git push
fi
cloud: 'aws'
language: 'Python'
outputDir: './artifact/pr_artifacts'
scanPath: './pr_branch'
targetCompute: 'k8s'
- name: Upload PR artifacts
uses: actions/upload-artifact@v4
with:
name: pr_branch_artifacts
path: ./artifact/pr_artifacts
- name: Generate diff between Main and PR branch
run: |
mkdir -p pr_branch/deployment_files
mv ./artifact/main/.appcd/charts/helm/scan_*/* pr_branch/deployment_files/
cd pr_branch
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add deployment_files
cd ./artifact/main/
git init
git config --local user.email "bot@appcd.com"
git config --local user.name "AppCD Bot"
git add .
git commit -m "staging deployment files from main to compare them"
rm -rf deploment_files
cd ..
mkdir -p pr_branch/deployment_files/
cp -R artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts/helm/scan_*/* pr_branch/deployment_files/
cd pr_branch
rm -rf *
cp -R ../pr_artifacts/* .
git add .
git diff --staged --output=../diff.txt deployment_files/ | cat
cat ../diff.txt
git diff --staged --output=../../diff.txt . | cat
cat ../../diff.txt
- name: Comment PR with IaC Changes
uses: actions/github-script@v6
with:
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@ jobs:
timeout-minutes: 10
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: pull latest
run: make pull
- name: Build image
run: make build
#- name: Test code format -- pre-commit
# run: make lint
- name: Generate IAC for main branch
env:
APPCD_TOKEN: ${{ secrets.APPCD_TOKEN }}
APPCD_URL: ${{ secrets.APPCD_URL }}
uses: appcd-dev/action@v0.0.1
with:
cloud: 'aws'
language: 'Python'
outputDir: './.appcd/charts'
scanPath: '.'
targetCompute: 'k8s'

21 changes: 12 additions & 9 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,20 @@ jobs:
- name: Create required directories
run: mkdir -p .appcd/charts && chmod 777 .appcd -R

- name: run appCD
run: |
docker run --rm \
--workdir=/code \
-v $PWD:/code ghcr.io/appcd-dev/appcd-dist/appcd-cli:v0.9.0 \
generate --mode ci --lang Python --iac-type Helm --output=/code/.appcd/charts
cd .appcd/charts && ls
unzip DogeAPI.zip && rm DogeAPI.zip

- name: Generate IAC for main branch
env:
APPCD_TOKEN: ${{ secrets.APPCD_TOKEN }}
APPCD_URL: ${{ secrets.APPCD_URL }}
uses: appcd-dev/action@v0.0.1
with:
cloud: 'aws'
language: 'Python'
outputDir: './.appcd/charts'
scanPath: './main_branch'
targetCompute: 'k8s'
- name: Inflate helm chart in gitops/
run: |
tree
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
helm template demo-chart ./.appcd/charts/dogeapi -f ./.appcd/overrides/dogeapi/values.yaml --set image.tag=${{ steps.version.outputs.image_tag }} > ./gitops/prod/dogeapi.yaml
else
Expand Down
Loading