-
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
5 changed files
with
103 additions
and
17 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 |
---|---|---|
@@ -1,25 +1,29 @@ | ||
name: Deploy | ||
name: Deploy production | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: self-hosted | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: Production | ||
url: https://myrt.co | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
- name: Build tar image | ||
run: sh -c scripts/build-tar.sh | ||
|
||
- name: Rebuild image | ||
run: npm run build:docker | ||
|
||
- name: Stop container | ||
run: npm run stop:docker | ||
|
||
- name: Start container | ||
run: npm run start:docker | ||
- name: Run deploy playbook | ||
uses: dawidd6/action-ansible-playbook@v2 | ||
with: | ||
playbook: deploy/playbook.yaml | ||
key: ${{secrets.SSH_PRIVATE_KEY}} | ||
options: | | ||
--inventory deploy/hosts.yaml | ||
--extra-vars target=production | ||
--verbose |
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,21 @@ | ||
FROM caddy:alpine | ||
ARG NODE_VERSION=21-alpine | ||
ARG PNPM_VERSION=8.13.1 | ||
ARG CADDY_VERSION=2.7-alpine | ||
|
||
FROM node:$NODE_VERSION as builder | ||
WORKDIR /build | ||
COPY src ./src | ||
COPY public ./public | ||
COPY \ | ||
package.json pnpm-lock.yaml \ | ||
tsconfig.json astro.config.mjs \ | ||
./ | ||
RUN npm install -g pnpm@$PNPM_VERSION | ||
RUN pnpm install --frozen-lockfile | ||
RUN pnpm build | ||
|
||
FROM caddy:$CADDY_VERSION | ||
COPY --from=builder /build/dist /data | ||
COPY Caddyfile /etc/caddy/Caddyfile | ||
COPY ./dist /data | ||
EXPOSE 80 | ||
EXPOSE 443 |
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,12 @@ | ||
all: | ||
hosts: | ||
production: | ||
hostnames: myrt.co | ||
# preview: | ||
# hostnames: preview.myrt.co | ||
vars: | ||
ansible_host: myrt.co | ||
ansible_user: runner | ||
ansible_ssh_common_args: -o ControlMaster=auto -o ControlPersist=1200s | ||
ansible_command_timeout: 30 | ||
ansible_ssh_retries: 3 |
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,42 @@ | ||
--- | ||
- hosts: "{{ target }}" | ||
name: Deploy myrt.co | ||
|
||
tasks: | ||
- name: Create temporary directory | ||
tempfile: | ||
state: directory | ||
suffix: web | ||
register: tempdir | ||
|
||
- name: Copy image archive | ||
retries: 3 | ||
delay: 1 | ||
synchronize: | ||
rsync_timeout: 60 | ||
src: "../dist/myrt-co.docker.tar" | ||
dest: "{{ tempdir.path }}/myrt-co.docker.tar" | ||
|
||
- name: Load image from the tar file | ||
community.docker.docker_image_load: | ||
path: "{{ tempdir.path }}/myrt-co.docker.tar" | ||
|
||
- name: Start container | ||
docker_container: | ||
image: "myrt-co:latest" | ||
recreate: true | ||
state: started | ||
name: "myrt-co-{{ target }}" | ||
ports: | ||
- 80:80 | ||
- 443:443 | ||
# labels: | ||
# caddy: "{{ hostnames }}" | ||
# caddy.reverse_proxy: "{% raw %}{{upstreams 80}}{% endraw %}" | ||
# networks: | ||
# - name: "caddy_proxy" | ||
|
||
- name: Remove temporary directory | ||
file: | ||
path: "{{ tempdir.path }}" | ||
state: absent |
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,10 @@ | ||
#!/bin/sh | ||
|
||
IMAGE_NAME="myrt-co" | ||
SERVER_PLATFORM="linux/amd64" | ||
DIST_DIR="dist" | ||
TAR_FILENAME="myrt-co.docker.tar" | ||
|
||
docker buildx build --load --platform "$SERVER_PLATFORM" -t "$IMAGE_NAME:latest" . | ||
mkdir -p "$DIST_DIR" | ||
docker save "$IMAGE_NAME:latest" > "${DIST_DIR}/${TAR_FILENAME}" |