-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
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,50 @@ | ||
name: CD | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up buildx for docker | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build Docker image and save | ||
id: build-docker | ||
run: | | ||
TAG_NAME=zoo-backend:$(git rev-parse --short HEAD) | ||
docker build -f infra/Dockerfile-deploy -t ${TAG_NAME} . | ||
docker save --output ${TAG_NAME}.tar ${TAG_NAME} | ||
echo "::set-output name=TAG_NAME::${TAG_NAME}" | ||
- name: Install cloudflared | ||
run: | | ||
lastest_version=$(curl -s $GITHUB_API_URL/repos/cloudflare/cloudflared/releases/latest | jq -r '.tag_name') | ||
mkdir -p /tmp/cloudflared | ||
curl -sL -o /tmp/cloudflared/cloudflared $GITHUB_SERVER_URL/cloudflare/cloudflared/releases/download/$lastest_version/cloudflared-linux-amd64 | ||
chmod +x /tmp/cloudflared/cloudflared | ||
/tmp/cloudflared/cloudflared --version | ||
- name: Setup SSH | ||
uses: shimataro/ssh-key-action@v2 | ||
with: | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
known_hosts: ${{ secrets.KNOWN_HOSTS }} | ||
name: id_ed25519 | ||
config: | | ||
Host server | ||
HostName ${{ secrets.HOST_NAME }} | ||
User ${{ secrets.USER_NAME }} | ||
IdentityFile ~/.ssh/id_ed25519 | ||
ProxyCommand /tmp/cloudflared/cloudflared access ssh --id ${{ secrets.SSH_CLOUDFLARED_ID }} --secret ${{ secrets.SSH_CLOUDFLARED_SECRET }} --hostname %h | ||
- name: Upload binary | ||
run: | | ||
rsync -vhz ${{ steps.build-docker.outputs.TAG_NAME }} server:~/ | ||
ssh server 'docker load --input ${{ steps.build-docker.outputs.TAG_NAME }}.tar && rm ${{ steps.build-docker.outputs.TAG_NAME }}.tar && docker stop $(docker ps -q) && docker run -d --restart always -p 8000:8000 ${{ steps.build-docker.outputs.TAG_NAME }}' | ||
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,16 @@ | ||
FROM rust:1 as build-env | ||
|
||
WORKDIR /app | ||
|
||
COPY . /app | ||
|
||
RUN cargo build --release | ||
|
||
|
||
FROM gcr.io/distroless/cc-debian12:nonroot | ||
|
||
USER nonroot | ||
|
||
COPY --chown=nonroot:nonroot --from=build-env /app/target/release/zoo_backend /home/nonroot/ | ||
|
||
CMD ["/home/nonroot/zoo_backend"] |