Skip to content

Commit

Permalink
Migrate to GitHub Container Registry (#2)
Browse files Browse the repository at this point in the history
kjagiello authored May 23, 2021

Verified

This commit was signed with the committer’s verified signature.
skitt Stephen Kitt
1 parent 4bf0617 commit 6074596
Showing 5 changed files with 22 additions and 19 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ on:
types: [published]

jobs:
push_to_registry:
name: Push Docker image to GitHub Packages
build_and_push:
name: Build and push Docker image to GitHub Container Registry
runs-on: ubuntu-latest
permissions:
packages: write
@@ -19,7 +19,7 @@ jobs:
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v1
with:
registry: docker.pkg.github.com
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

@@ -28,6 +28,6 @@ jobs:
with:
push: true
tags: |
docker.pkg.github.com/${{ github.repository }}/pacgen:${{ github.sha }}
docker.pkg.github.com/${{ github.repository }}/pacgen:${{ github.event.release.tag_name }}
docker.pkg.github.com/${{ github.repository }}/pacgen:latest
ghcr.io/${{ github.repository_owner }}/pacgen:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/pacgen:${{ github.event.release.tag_name }}
ghcr.io/${{ github.repository_owner }}/pacgen:latest
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -9,13 +9,13 @@ Easily create a PAC file from a TOML config.
You can generate a PAC file from a TOML file using the latest stable pacgen Docker image:

```shell
cat pac.toml | docker run --rm -i docker.pkg.github.com/kjagiello/pacgen/pacgen:latest -
cat pac.toml | docker run --rm -i ghcr.io/kjagiello/pacgen:latest -
```

You can also serve this file (the HTTP server binds by default at `127.0.0.1:8000`):

```shell
cat pac.toml | docker run --rm -i docker.pkg.github.com/kjagiello/pacgen/pacgen:latest -s -
cat pac.toml | docker run --rm -i ghcr.io/kjagiello/pacgen:latest -s -
```

### CLI documentation
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -52,14 +52,14 @@ pub fn main() -> io::Result<()> {
.short("h")
.requires("serve")
.takes_value(true)
.help("Host to bind the PAC server to"),
.help("Host to bind the PAC server at [default: 127.0.0.1]"),
)
.arg(
Arg::with_name("port")
.short("p")
.takes_value(true)
.requires("serve")
.help("Port to bind the PAC server to"),
.help("Port to bind the PAC server at [default: 8080]"),
)
.arg(
Arg::with_name("CONFIG")
17 changes: 9 additions & 8 deletions src/generator.rs
Original file line number Diff line number Diff line change
@@ -18,15 +18,16 @@ fn build_addr(addr: &Address) -> String {
}

fn build_proxy(proxy: Arc<Proxy>) -> String {
let proxy_config = match *proxy {
Proxy::Direct => "DIRECT".to_owned(),
Proxy::Socks(ref addr) => format!("SOCKS {}", build_addr(&addr)),
Proxy::Socks4(ref addr) => format!("SOCKS4 {}", build_addr(&addr)),
Proxy::Socks5(ref addr) => format!("SOCKS5 {}", build_addr(&addr)),
Proxy::Http(ref addr) => format!("HTTP {}", build_addr(&addr)),
Proxy::Https(ref addr) => format!("HTTPS {}", build_addr(&addr)),
let (name, addr) = match *proxy {
Proxy::Direct => ("DIRECT", None),
Proxy::Socks(ref addr) => ("SOCKS", Some(addr)),
Proxy::Socks4(ref addr) => ("SOCKS4", Some(addr)),
Proxy::Socks5(ref addr) => ("SOCKS5", Some(addr)),
Proxy::Http(ref addr) => ("HTTP", Some(addr)),
Proxy::Https(ref addr) => ("HTTPS", Some(addr)),
};
proxy_config
addr.map(|addr| format!("{} {}", name, build_addr(addr)))
.unwrap_or_else(|| name.to_owned())
}

fn build_rules(config: &Config) -> Vec<Rule> {
4 changes: 3 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
@@ -30,7 +30,9 @@ fn log_request<T, U>(remote_addr: &SocketAddr, req: &Request<T>, response: &Resp

#[tokio::main]
pub async fn serve(config: Config) {
let ctx = Arc::new(Context { pac: config.pac });
let ctx = Arc::new(Context {
pac: config.pac.trim_end().to_owned(),
});

let make_service = make_service_fn(move |conn: &AddrStream| {
let ctx = ctx.clone();

0 comments on commit 6074596

Please sign in to comment.