Skip to content

Commit adb8e1a

Browse files
committed
Add: Backup
0 parents  commit adb8e1a

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

.github/workflows/cicd.yml

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Build Image & Push an Image to ECR (CI)
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
env:
8+
AWS_REGION: "ap-northeast-2"
9+
10+
permissions:
11+
id-token: write
12+
contents: write
13+
14+
jobs:
15+
ci:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
IMAGE_TAG: ${{ steps.set-var.outputs.IMAGE_TAG }}
19+
steps:
20+
- name: Git-Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Configure AWS Credentials
24+
uses: aws-actions/configure-aws-credentials@v3
25+
with:
26+
role-to-assume: ${{ secrets.ARN_ECR_PUSH_ROLE }}
27+
role-session-name: Private-ECR-PushRole
28+
aws-region: ${{ env.AWS_REGION }}
29+
30+
- name: Login ECR
31+
id: login-ecr
32+
uses: aws-actions/amazon-ecr-login@v2
33+
34+
- name: Set variable
35+
id: set-variable
36+
run: |
37+
echo "ECR_REGISTRY=${{ steps.login-ecr.outputs.registry }}" >> $GITHUB_ENV
38+
echo "ECR_REPOSITORY=ejl-repo" >> $GITHUB_ENV
39+
echo "IMAGE_TAG=${{ github.sha }}" >> $GITHUB_ENV
40+
41+
- name: Set up Docker buildx
42+
uses: docker/setup-buildx-action@v1
43+
44+
#- name: Cache Docker layers
45+
# uses: actions/cache@v2
46+
# with:
47+
# path: /tmp/.buildx-cache
48+
# key: ${{ runner.os }}-buildx-${{ github.sha }}
49+
# restore-keys: |
50+
# ${{ runner.os }}-buildx-
51+
52+
#- name: Docker Build & Push
53+
# uses: docker/build-push-action@v2
54+
# with:
55+
# context: .
56+
# file: ./Dockerfile
57+
# push: true
58+
# tags: $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
59+
# cache-from: type=local,src=/tmp/.buildx-cache
60+
# cache-to: type=local,dest=/tmp/.buildx-cache
61+
- name: Docker build
62+
id: build-image
63+
run: |
64+
docker build \
65+
-f Dockerfile \
66+
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
67+
68+
- name: Docker Image Push
69+
id: image-push
70+
run: |
71+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
72+
73+
- name: Checkout for Kustomize repository
74+
uses: actions/checkout@v2
75+
with:
76+
# kubernetes yaml 파일 저장
77+
repository: Leeeuijooo/Kustomize_test
78+
ref: main
79+
token: ${{ secrets.ACTION_TOKEN }} # Repository Token 은 미리 발급받야아합니다.
80+
path: Kustomize_test
81+
82+
- name: Update k8s resource
83+
run: |
84+
pwd
85+
cd Kustomize_test/overlays/dev
86+
echo \${{ steps.login-ecr.outputs.registry }}/\${{ env.ECR_REPOSITORY }}:$IMAGE_TAG
87+
kustomize edit set image \${{ steps.login-ecr.outputs.registry }}/\${{ env.ECR_REPOSITORY }}=\${{ steps.login-ecr.outputs.registry }}/\${{ env.ECR_REPOSITORY }}:$IMAGE_TAG
88+
cat kustomization.yml
89+
90+
- name: Commit Manifest files
91+
run: |
92+
cd Kustomize_test
93+
git config --global user.email "[email protected]"
94+
git config --global user.name "euijoo"
95+
git add .
96+
git commit -m "Update Manifest file Image Tag $IMAGE_TAG"
97+
git push -u origin main
98+
99+
100+
- name: action-slack
101+
uses: 8398a7/action-slack@v3
102+
with:
103+
status: ${{ job.status }}
104+
author_name: Leeeuijooo-gitactions-test
105+
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took
106+
env:
107+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
108+
if: always()
109+

Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.8-slim-buster
2+
3+
WORKDIR /app
4+
5+
RUN pip install flask
6+
7+
COPY . /app
8+
9+
CMD [ "python", "-m" , "flask", "run", "--host=0.0.0.0", "--port=5000"]
10+

app.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from flask import Flask
2+
3+
app = Flask(__name__)
4+
5+
@app.route('/')
6+
def hello_world():
7+
return 'git pull test'
8+
9+
if __name__ == '__main__':
10+
app.run(host='0.0.0.0', port=5000)
11+

0 commit comments

Comments
 (0)