mirror of
https://github.com/NetworkCats/rustyip.git
synced 2026-11-13 16:17:46 +00:00
feat: switch container registry from GHCR to Docker Hub
This commit is contained in:
@@ -7,12 +7,10 @@ on:
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
IMAGE_NAME: networkcat/rustyip
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
# ---- CI checks ----
|
||||
@@ -62,18 +60,17 @@ jobs:
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to GHCR
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
images: ${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=semver,pattern={{version}}
|
||||
type=raw,value=latest
|
||||
@@ -92,7 +89,7 @@ jobs:
|
||||
id: full_image
|
||||
run: |
|
||||
TAG="${GITHUB_REF_NAME#v}"
|
||||
echo "image=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}" >> "$GITHUB_OUTPUT"
|
||||
echo "image=${{ env.IMAGE_NAME }}:${TAG}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# ---- Deploy to VPS ----
|
||||
deploy:
|
||||
@@ -199,8 +196,8 @@ jobs:
|
||||
DB_UPDATE_URL: ${{ secrets.DB_UPDATE_URL }}
|
||||
ORIGIN_CERT: ${{ secrets.ORIGIN_CERT }}
|
||||
ORIGIN_KEY: ${{ secrets.ORIGIN_KEY }}
|
||||
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GHCR_USER: ${{ github.actor }}
|
||||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
FIRST_DEPLOY: ${{ steps.detect.outputs.first_deploy }}
|
||||
run: |
|
||||
ansible-playbook -i inventory.yml playbook.yml
|
||||
|
||||
+8
-3
@@ -31,13 +31,13 @@ docker compose up --build
|
||||
Pushing a version tag (e.g. `v1.0.0`) triggers the full deployment pipeline:
|
||||
|
||||
```
|
||||
v* tag push --> CI checks --> Docker build + push to GHCR --> Terraform + Ansible deploy
|
||||
v* tag push --> CI checks --> Docker build + push to Docker Hub --> Terraform + Ansible deploy
|
||||
```
|
||||
|
||||
### Pipeline Overview
|
||||
|
||||
1. **Check** -- Runs `cargo fmt`, `cargo clippy`, and `cargo test`.
|
||||
2. **Build** -- Builds a Docker image and pushes it to GitHub Container Registry (`ghcr.io`).
|
||||
2. **Build** -- Builds a Docker image and pushes it to Docker Hub (`docker.io/networkcat/rustyip`).
|
||||
3. **Deploy** -- Provisions infrastructure with Terraform and configures/deploys with Ansible.
|
||||
|
||||
The deploy job uses a `production` environment with concurrency control to prevent overlapping deployments.
|
||||
@@ -79,7 +79,12 @@ If you are using environments, add them under the `production` environment (**Se
|
||||
| `ORIGIN_CERT` | Cloudflare Origin certificate (PEM) for TLS termination at HAProxy |
|
||||
| `ORIGIN_KEY` | Corresponding private key (PEM) for the Origin certificate |
|
||||
|
||||
`GITHUB_TOKEN` is provided automatically by GitHub Actions and does not need to be configured. It is used to authenticate with GHCR.
|
||||
#### Docker Hub
|
||||
|
||||
| Secret | Description |
|
||||
|---|---|
|
||||
| `DOCKERHUB_USERNAME` | Docker Hub username used for image push and pull |
|
||||
| `DOCKERHUB_TOKEN` | Docker Hub access token for authentication |
|
||||
|
||||
### Deploying
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
db_update_url: "{{ lookup('env', 'DB_UPDATE_URL') }}"
|
||||
origin_cert: "{{ lookup('env', 'ORIGIN_CERT') }}"
|
||||
origin_key: "{{ lookup('env', 'ORIGIN_KEY') }}"
|
||||
ghcr_token: "{{ lookup('env', 'GHCR_TOKEN') }}"
|
||||
ghcr_user: "{{ lookup('env', 'GHCR_USER') }}"
|
||||
dockerhub_token: "{{ lookup('env', 'DOCKERHUB_TOKEN') }}"
|
||||
dockerhub_username: "{{ lookup('env', 'DOCKERHUB_USERNAME') }}"
|
||||
first_deploy: "{{ lookup('env', 'FIRST_DEPLOY') | default('false', true) }}"
|
||||
|
||||
roles:
|
||||
|
||||
@@ -40,9 +40,9 @@
|
||||
group: root
|
||||
mode: "0600"
|
||||
|
||||
- name: Log in to GHCR
|
||||
- name: Log in to Docker Hub
|
||||
ansible.builtin.shell: |
|
||||
echo "{{ ghcr_token }}" | docker login ghcr.io -u "{{ ghcr_user }}" --password-stdin
|
||||
echo "{{ dockerhub_token }}" | docker login -u "{{ dockerhub_username }}" --password-stdin
|
||||
no_log: true
|
||||
changed_when: true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user