-
Notifications
You must be signed in to change notification settings - Fork 289
Lab9 #3258
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
base: master
Are you sure you want to change the base?
Lab9 #3258
Changes from all commits
7ff55d7
a057c02
2fbd476
9a363bf
e391e97
888cd53
2b850a9
c871131
d57fde0
e801e7b
16275c8
f1d3f8a
a881a7c
3f6013d
b3a6453
70b559e
fade416
8f06356
f59d14b
3de805d
786485f
564523c
5d80eed
3d9cad1
b538024
10a6199
69d443b
ee7b641
ab26608
b3e811a
832e7de
963c207
84a2562
c6dff04
997c3d2
d899f9b
accf74a
09d9f22
4729759
c654d50
f0d3f10
7603507
d2b5cde
895adea
516f737
de270bf
8e010c4
6b73b6f
cd9ba43
fe1695a
3677264
0761be3
9a92b25
de53b08
4d5cee1
9c9dad5
5ad68fd
b0baf81
49176cd
87d709f
1c84430
3c42110
7f6e584
f4331b5
1ff417c
216005f
e88d134
c697066
1150843
3df5131
afc7e79
c4d1541
ccc65be
c0aefd5
a25cbba
d7fe44a
3ddd08a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||||||
| name: Ansible Deployment | ||||||||||
|
|
||||||||||
| on: | ||||||||||
| push: | ||||||||||
| branches: [main, master, lab*] | ||||||||||
| paths: | ||||||||||
| - "labs/ansible/**" | ||||||||||
| - ".github/workflows/ansible-deploy.yaml" | ||||||||||
| pull_request: | ||||||||||
| branches: [main, master, lab*] | ||||||||||
| paths: | ||||||||||
| - "labs/ansible/**" | ||||||||||
|
|
||||||||||
| jobs: | ||||||||||
| lint: | ||||||||||
| name: Ansible Lint | ||||||||||
| runs-on: ubuntu-latest | ||||||||||
| steps: | ||||||||||
| - name: Checkout code | ||||||||||
| uses: actions/checkout@v4 | ||||||||||
|
|
||||||||||
| - name: Set up Python | ||||||||||
| uses: actions/setup-python@v5 | ||||||||||
| with: | ||||||||||
| python-version: "3.12" | ||||||||||
|
|
||||||||||
| - name: Install dependencies | ||||||||||
| run: | | ||||||||||
| pip install ansible ansible-lint | ||||||||||
|
|
||||||||||
| - name: Run ansible-lint | ||||||||||
| run: | | ||||||||||
| cd labs/ansible | ||||||||||
| ansible-lint playbooks/*.yaml | ||||||||||
|
|
||||||||||
| deploy: | ||||||||||
| name: Deploy Application | ||||||||||
| needs: lint | ||||||||||
| runs-on: self-hosted | ||||||||||
| steps: | ||||||||||
| - name: Checkout code | ||||||||||
| uses: actions/checkout@v4 | ||||||||||
|
|
||||||||||
| - name: Set up Python | ||||||||||
| uses: actions/setup-python@v5 | ||||||||||
| with: | ||||||||||
| python-version: "3.12" | ||||||||||
|
|
||||||||||
| - name: Install Ansible | ||||||||||
| run: | | ||||||||||
| python -m pip install --upgrade pip | ||||||||||
| pip install ansible | ||||||||||
|
|
||||||||||
| - name: Deploy with Ansible | ||||||||||
| env: | ||||||||||
| ANSIBLE_VAULT_PASSWORD: ${{ secrets.ANSIBLE_VAULT_PASSWORD }} | ||||||||||
| run: | | ||||||||||
| cd labs/ansible | ||||||||||
| echo "$ANSIBLE_VAULT_PASSWORD" > /tmp/vault_pass | ||||||||||
| ansible-playbook playbooks/deploy.yaml \ | ||||||||||
| -i inventory/hosts.ini \ | ||||||||||
| --vault-password-file /tmp/vault_pass \ | ||||||||||
| --tags "app_deploy" | ||||||||||
| rm /tmp/vault_pass | ||||||||||
|
|
||||||||||
| - name: Verify Deployment | ||||||||||
| run: | | ||||||||||
| sleep 10 | ||||||||||
| curl -f http://${{ secrets.VM_HOST }}:8000 || exit 1 | ||||||||||
| curl -f http://${{ secrets.VM_HOST }}:8000/health || exit 1 | ||||||||||
|
Comment on lines
+69
to
+70
|
||||||||||
| curl -f http://${{ secrets.VM_HOST }}:8000 || exit 1 | |
| curl -f http://${{ secrets.VM_HOST }}:8000/health || exit 1 | |
| curl -f http://${{ secrets.VM_HOST }}:5000 || exit 1 | |
| curl -f http://${{ secrets.VM_HOST }}:5000/health || exit 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| name: Java CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: ["main", "lab*"] | ||
| paths: | ||
| - "labs/app_java/**" | ||
| - ".github/workflows/java-ci.yml" | ||
| pull_request: | ||
| branches: ["main", "lab*"] | ||
| paths: | ||
| - "labs/app_java/**" | ||
|
|
||
| jobs: | ||
| build-and-test: | ||
| if: "!contains(github.event.head_commit.message, 'docs')" | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: ./labs/app_java | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: "17" | ||
| distribution: "temurin" | ||
| cache: "maven" | ||
|
|
||
| - name: Run Linting | ||
| run: mvn checkstyle:check | ||
|
|
||
| - name: Build and Test | ||
| run: mvn clean verify | ||
|
|
||
| - name: Install Snyk CLI | ||
| uses: snyk/actions/setup@master | ||
|
|
||
| - name: Run Snyk | ||
| env: | ||
| SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | ||
| run: snyk test | ||
| continue-on-error: true | ||
|
|
||
| docker-build: | ||
| needs: build-and-test | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'push' | ||
| defaults: | ||
| run: | ||
| working-directory: ./labs/app_java | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Log in to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_TOKEN }} | ||
|
|
||
| - name: Extract metadata (tags, labels) for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ${{ secrets.DOCKER_USERNAME }}/devops-app-java | ||
| tags: | | ||
| type=semver,pattern={{version}} | ||
| type=raw,value=latest | ||
| type=sha | ||
|
|
||
| - name: Build and push Docker image | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: ./labs/app_java | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| name: Python CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [lab*, main] | ||
| paths: | ||
| - "labs/app_python/**" | ||
| tags: | ||
| - "v*" | ||
| pull_request: | ||
| paths: | ||
| - "labs/app_python/**" | ||
|
|
||
| jobs: | ||
| test-and-lint: | ||
| runs-on: ubuntu-latest | ||
| if: "!contains(github.event.head_commit.message, 'docs') && !contains(github.event.pull_request.title, 'docs')" | ||
| defaults: | ||
| run: | ||
| working-directory: labs/app_python | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: "3.12.3" | ||
|
|
||
| - name: Install dev dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -r requirements-dev.txt | ||
|
|
||
| - name: Install Snyk CLI | ||
| run: | | ||
| curl -Lo ./snyk https://github.com/snyk/cli/releases/latest/download/snyk-linux | ||
| chmod +x ./snyk | ||
| sudo mv ./snyk /usr/local/bin/ | ||
|
|
||
| - name: Run Snyk | ||
| env: | ||
| SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | ||
| run: | | ||
| snyk auth $SNYK_TOKEN | ||
| snyk test | ||
|
|
||
| - name: Lint code | ||
| run: | | ||
| flake8 . | ||
|
|
||
| - name: Run tests | ||
| run: | | ||
| pytest -v | ||
|
|
||
| build-and-push: | ||
| runs-on: ubuntu-latest | ||
| needs: test-and-lint | ||
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/lab') || startsWith(github.ref, 'refs/tags/v')) | ||
| defaults: | ||
| run: | ||
| working-directory: labs/app_python | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Log in to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_TOKEN }} | ||
|
|
||
| - name: Extract metadata (tags, labels) | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ${{ secrets.DOCKER_USERNAME }}/python-info-service | ||
| tags: | | ||
| type=ref,event=branch | ||
| type=sha,prefix={{date 'YYYYMMDD'}}- | ||
| type=raw,value=latest | ||
|
|
||
| - name: Build and push Docker image | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: labs/app_python | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/python-info-service:buildcache | ||
| cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/python-info-service:buildcache,mode=max |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: Terraform CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: ["main", "lab*"] | ||
| paths: | ||
| - "labs/terraform/**" | ||
| pull_request: | ||
| paths: | ||
| - "labs/terraform/**" | ||
|
|
||
| jobs: | ||
| terraform: | ||
| name: Terraform Validate | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: labs/terraform | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Terraform | ||
| uses: hashicorp/setup-terraform@v3 | ||
| with: | ||
| terraform_version: "1.10.0" | ||
|
|
||
| - name: Setup TFLint | ||
| uses: terraform-linters/setup-tflint@v4 | ||
| with: | ||
| tflint_version: v0.50.0 | ||
|
|
||
| - name: Terraform Format Check | ||
| run: terraform fmt -check | ||
|
|
||
| - name: Terraform Init | ||
| run: terraform init -backend=false | ||
|
|
||
| - name: Terraform Validate | ||
| run: terraform validate | ||
|
|
||
| - name: TFLint Init | ||
| run: tflint --init | ||
|
|
||
| - name: Run TFLint | ||
| run: tflint --format=compact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deploy job runs
ansible-playbookbut doesn’t install required collections. This repo usescommunity.docker.*modules in the roles, which will fail unlesscommunity.dockeris installed on the runner (and potentiallyamazon.awsif using the dynamic inventory). Add anansible-galaxy collection installstep (or acollections/requirements.yml) before running the playbook.