-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: ci-cd 설정 #2
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d97782e
feat: set up test api
iamjooon2 924d8c5
feat: write up Dockerfile
iamjooon2 7c0309d
feat: write ci.yml
iamjooon2 1f56768
feat: write cd.yml
iamjooon2 d33f34a
build: add godotenv dependency
iamjooon2 8809a42
feat: apply env file
iamjooon2 4426e64
fix: use docker action
iamjooon2 12fe560
fix: change build method
iamjooon2 14a30b2
fix: remove unnecessary go setup
iamjooon2 5741b85
chore: add crlf to preserve EOF consistency
iamjooon2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: backend deploy | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name : create .env file | ||
run : echo "${{secrets.env}}" >> .env | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{secrets.DOCKER_HUB_USERNAME}} | ||
password: ${{secrets.DOCKER_HUB_TOKEN}} | ||
|
||
# Docker Build & Push | ||
- name: Docker Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
platforms: linux/amd64 | ||
push: true | ||
tags: | | ||
${{ secrets.DOCKER_HUB_USERNAME }}/server:${{github.run_number}} | ||
${{ secrets.DOCKER_HUB_USERNAME }}/server:latest | ||
|
||
deploy: | ||
runs-on: self-hosted | ||
steps: | ||
- name: change permission | ||
run: | | ||
sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/server | ||
- uses: actions/checkout@v3 | ||
|
||
- name: deploy | ||
run: cd /home/ubuntu && sudo ./deploy.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: backend test for PR to main | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22.5 | ||
|
||
- name: Build file | ||
run: go build ./cmd/main.go | ||
|
||
- name: Test with the Go CLI | ||
run: go test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
|
||
.idea | ||
.env |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
FROM golang:1.22.5 | ||
|
||
# Set destination for COPY | ||
WORKDIR /app | ||
|
||
# Download Go modules | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
# Copy the source code. Note the slash at the end, as explained in | ||
# https://docs.docker.com/reference/dockerfile/#copy | ||
COPY *.go ./ | ||
|
||
# Build | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o /techbloghub-server | ||
|
||
Comment on lines
+3
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그 스테이지라고 하던가 분리해서 빌드용 배포용 베이스 이미지 다르게 하는것도 후에 찾아보면 좋을듯? 일단 위에서 내가 코멘트 남긴것처럼 해당 브렌치에서 배포 동작시켜보고 배포 잘 되는거 확인 된 다음에 도커 이미지파일 수정해가면서 잘 되나 안되나 테스트 하는 방향으로? 나중에 나도 어케하나 더 찾아보게되면 코멘트로 추가 남기거나 디코에 올려둠요 |
||
# Optional: | ||
# To bind to a TCP port, runtime parameters must be supplied to the docker command. | ||
# But we can document in the Dockerfile what ports | ||
# the application is going to listen on by default. | ||
# https://docs.docker.com/reference/dockerfile/#expose | ||
EXPOSE 8080 | ||
|
||
# Run | ||
CMD ["/techbloghub-server"] |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/joho/godotenv" | ||
"os" | ||
) | ||
|
||
func main() { | ||
env := godotenv.Load(".env") | ||
if env != nil { | ||
return | ||
} | ||
r := SetRouter() | ||
err := r.Run(":" + os.Getenv("PORT")) | ||
if err != nil { | ||
return | ||
} | ||
} | ||
|
||
func SetRouter() *gin.Engine { | ||
r := gin.Default() | ||
r.GET("/ping", func(context *gin.Context) { | ||
context.String(200, "pong") | ||
}) | ||
return r | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
테스트 할 수 있는 꿀팁!!
위처럼 해두면 이거 테스트한다고 계속 main에 머지해보고 할 필요 없이 해당 브렌치에 테스트로 계속 푸시해보면서 해당 워크플로우 동작시켜서 배포 테스트 할 수 있어용
테스트 다 되고 마지막에 이거 머지시키기 전에 해당부분
-chore/ci-cd
부분 제거하고 머지시키면 되고용